Skip to content

Commit

Permalink
assorted updates (#18)
Browse files Browse the repository at this point in the history
- fix cran issues
- fix compatibility with Matrix pkg updates
- fix typos in documentation
- rename macosx to macos
- update cran comments
  • Loading branch information
jeffreyhanson authored Sep 7, 2022
1 parent dda0181 commit abc9a6a
Show file tree
Hide file tree
Showing 208 changed files with 12,186 additions and 17,918 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ check.log
test.log
gp.log
spell.log
examples.log
README.Rmd
inst/extdata/dictionary.txt
^_pkgdown\.yml$
^CONTRIBUTING\.md$
^CONTRIBUTING\.Rmd$
^CRAN-RELEASE$
^\.github$
inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- main
- master

name: Mac OSX
name: macOS

jobs:
R-CMD-check:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test.log
check.log
spell.log
gp.log
examples.log
# system files
.directory
# do not ignore the following files
Expand Down
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: oppr
Type: Package
Version: 1.0.3
Version: 1.0.4
Title: Optimal Project Prioritization
Description: A decision support tool for prioritizing conservation projects.
Prioritizations can be developed by maximizing expected feature richness,
Expand Down Expand Up @@ -51,8 +51,8 @@ Suggests:
roxygen2 (>= 6.1.0),
rmarkdown (>= 1.10),
gurobi (>= 8.0.0),
ggtree (>= 2.4.2),
Rsymphony (>= 0.1.28),
ggtree (>= 2.4.2),
lpsymphony (>= 1.10.0),
shiny (>= 1.2.0),
rhandsontable (>= 0.3.7),
Expand All @@ -69,8 +69,9 @@ SystemRequirements: C++11
URL: https://prioritizr.github.io/oppr/
BugReports: https://github.com/prioritizr/oppr/issues
VignetteBuilder: knitr
RoxygenNote: 7.1.1
RoxygenNote: 7.2.1
Encoding: UTF-8
Language: en-US
Collate:
'internal.R'
'pproto.R'
Expand Down
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ quickcheck:

check:
echo "\n===== R CMD CHECK =====\n" > check.log 2>&1
R --slave -e "devtools::check(build_args = '--no-build-vignettes', args = '--no-build-vignettes', run_dont_test = TRUE, vignettes = FALSE)" >> check.log 2>&1
R --slave -e "devtools::check(remote = TRUE, build_args = '--no-build-vignettes', args = '--no-build-vignettes', run_dont_test = TRUE, vignettes = FALSE)" >> check.log 2>&1
cp -Rf doc inst/
touch inst/doc/.gitkeep

Expand All @@ -66,7 +66,17 @@ quickbuild:
R --slave -e "devtools::build(vignettes = FALSE)"
cp -Rf doc inst/

urlcheck:
R --slave -e "devtools::document();urlchecker::url_check()"

spellcheck:
R --slave -e "devtools::document();devtools::spell_check()"

examples:
R --slave -e "devtools::run_examples(run_donttest = TRUE, run_dontrun = TRUE);warnings()" > examples.log 2>&1
rm -f Rplots.pdf

install:
R --slave -e "devtools::install_local('../oppr', force = TRUE, upgrade = 'never')"
R --slave -e "devtools::install_local('.', force = TRUE, upgrade = 'never')"

.PHONY: initc data docs readme site test check checkwb build install man
26 changes: 18 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# oppr 1.0.3 (released)
# oppr 1.0.4

- CRAN release.
- Fix compiler warnings raised by CRAN checks.
- Remove references to the *ggtree* package in documentation.
- Fix memory issues encountered during installation on CRAN Windows server.
- Fix compatibility issues with upcoming version of the *Matrix* package
(version 1.4-2).
- Fix broken URLs in package documentation.

# oppr 1.0.3

- CRAN release.
- Fix URLs for CRAN.
Expand Down Expand Up @@ -46,23 +56,23 @@
- Fix "Non-file package-anchored link(s) in documentation object" warnings in
R-devel checks.

# oppr 1.0.2 (released)
# oppr 1.0.2

- CRAN release.

# oppr 1.0.1.1

- Replace `tibble::as.tibble` with `tibble::as_tibble` to avoid warnings.

# oppr 1.0.1 (released)
# oppr 1.0.1

- CRAN release.

# oppr 1.0.0.1

- Fix compatibility issues with upcoming _tibble_ (3.0.0) R package.

# oppr 1.0.0 (released)
# oppr 1.0.0

- CRAN release.

Expand All @@ -71,7 +81,7 @@
- Fix warnings in R-devel CRAN checks related to documentation.
- Add citation for the research article that accompanies this package.

# oppr 0.0.4 (released)
# oppr 0.0.4

- CRAN release.

Expand All @@ -80,15 +90,15 @@
- Fix typo.
- Fix broken links to Gurobi academic licenses.

# oppr 0.0.3 (released)
# oppr 0.0.3

- CRAN release.

# oppr 0.0.2.1

- Retain debugging symbols to conform with CRAN policies.

# oppr 0.0.2 (released)
# oppr 0.0.2

- CRAN release.

Expand All @@ -97,7 +107,7 @@
- Fix address sanitizer issues causing CRAN checks to fail.
- Tests successfully complete when the _shiny_ R package is not installed.

# oppr 0.0.1 (released)
# oppr 0.0.1

- CRAN release.

Expand Down
18 changes: 10 additions & 8 deletions R/ProjectProblem-proto.R
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ ProjectProblem <- pproto(
self$project_names())
},
pf_matrix = function(self) {
m <- methods::as(as.matrix(
m <- as_Matrix(as.matrix(
self$data$projects[, self$data$features[[self$data$feature_name_column]],
drop = FALSE]), "dgCMatrix")
m@x[is.na(m@x)] <- 0
Expand All @@ -410,11 +410,13 @@ ProjectProblem <- pproto(
},
epf_matrix = function(self) {
# extract persistence probabilities, but not accounting for baseline
m <- as(self$pf_matrix() * matrix(self$project_success_probabilities(),
ncol = self$number_of_features(),
nrow = self$number_of_projects()),
"dgCMatrix")
m <- as(m, "dgCMatrix")
m <- as_Matrix(
self$pf_matrix() *
matrix(self$project_success_probabilities(),
ncol = self$number_of_features(),
nrow = self$number_of_projects()),
"dgCMatrix")
m <- as_Matrix(m, "dgCMatrix")
m <- Matrix::drop0(m)
# if include baseline probabilities, then account for probabilities of
# each project persisting and the baseline project not failing
Expand All @@ -430,15 +432,15 @@ ProjectProblem <- pproto(
## overwrite baseline data
m[bp, ] <- bpp
## coerce data type
m <- as(m, "dgCMatrix")
m <- as_Matrix(m, "dgCMatrix")
m <- Matrix::drop0(m)
}
rownames(m) <- self$project_names()
colnames(m) <- self$feature_names()
m
},
pa_matrix = function(self) {
m <- methods::as(as.matrix(
m <- as_Matrix(as.matrix(
self$data$projects[, self$data$actions[[self$data$action_name_column]],
drop = FALSE]), "dgCMatrix")
rownames(m) <- self$data$projects[[self$data$project_name_column]]
Expand Down
2 changes: 1 addition & 1 deletion R/add_lpsolveapi_solver.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ add_lpsolveapi_solver <- function(x, gap = 0, presolve = FALSE,
# extract parameters
p <- as.list(self$parameters)
# extract constraints
m <- methods::as(x$A(), "dgTMatrix")
m <- as_Matrix(x$A(), "dgTMatrix")
mrhs <- x$rhs()
msense <- x$sense()
# manually add in locked constraints
Expand Down
2 changes: 1 addition & 1 deletion R/add_lpsymphony_solver.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NULL
#'
#' @inheritParams add_gurobi_solver
#'
#' @details [*SYMPHONY*](https://projects.coin-or.org/SYMPHONY) is an
#' @details [*SYMPHONY*](https://github.com/coin-or/SYMPHONY) is an
#' open-source integer programming solver that is part of the Computational
#' Infrastructure for Operations Research (COIN-OR) project, an initiative
#' to promote development of open-source tools for operations research (a
Expand Down
2 changes: 1 addition & 1 deletion R/add_max_phylo_div_objective.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ add_max_phylo_div_objective <- function(x, budget, tree) {
bm[, bo, drop = FALSE], fp$edge.length[bo],
rep(0, y$number_of_features()),
y$feature_weights()[fp$tip.label],
methods::as(as.matrix(solution), "dgCMatrix"))
as_Matrix(as.matrix(solution), "dgCMatrix"))
},
apply = function(self, x, y) {
assertthat::assert_that(inherits(x, "OptimizationProblem"),
Expand Down
2 changes: 1 addition & 1 deletion R/add_max_richness_objective.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ add_max_richness_objective <- function(x, budget) {
y$epf_matrix()[, y$feature_phylogeny()$tip.label, drop = FALSE],
bm[, bo, drop = FALSE], rep(0, ncol(bm)),
rep(0, y$number_of_features()), w,
methods::as(as.matrix(solution), "dgCMatrix"))
as_Matrix(as.matrix(solution), "dgCMatrix"))
},
apply = function(self, x, y) {
assertthat::assert_that(inherits(x, "OptimizationProblem"),
Expand Down
2 changes: 1 addition & 1 deletion R/add_max_targets_met_objective.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ add_max_targets_met_objective <- function(x, budget) {
y$action_costs(), y$pa_matrix(), y$epf_matrix(),
bm[, bo, drop = FALSE], fp$edge.length[bo],
y$targets$output()$value, w,
methods::as(as.matrix(solution), "dgCMatrix"))
as_Matrix(as.matrix(solution), "dgCMatrix"))
},
apply = function(self, x, y) {
assertthat::assert_that(inherits(x, "OptimizationProblem"),
Expand Down
2 changes: 1 addition & 1 deletion R/add_min_set_objective.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ add_min_set_objective <- function(x) {
y$epf_matrix()[, y$feature_phylogeny()$tip.label, drop = FALSE],
bm[, bo, drop = FALSE], fp$edge.length[bo],
rep(0, y$number_of_features()), rep(0, y$number_of_features()),
methods::as(as.matrix(solution), "dgCMatrix"))
as_Matrix(as.matrix(solution), "dgCMatrix"))
},
apply = function(self, x, y) {
assertthat::assert_that(inherits(x, "OptimizationProblem"),
Expand Down
2 changes: 1 addition & 1 deletion R/add_rsymphony_solver.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NULL
#'
#' @inheritParams add_gurobi_solver
#'
#' @details [*SYMPHONY*](https://projects.coin-or.org/SYMPHONY) is an
#' @details [*SYMPHONY*](https://github.com/coin-or/SYMPHONY) is an
#' open-source integer programming solver that is part of the Computational
#' Infrastructure for Operations Research (COIN-OR) project, an initiative
#' to promote development of open-source tools for operations research (a
Expand Down
2 changes: 1 addition & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ NULL

#' Simulated data
#'
#' Simulated data for prioritizing conservations projects.
#' Simulated data for prioritizing conservation projects.
#'
#' @usage data(sim_actions)
#' @usage data(sim_projects)
Expand Down
58 changes: 58 additions & 0 deletions R/internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,61 @@ lp_solve_status <- function(x) {
warning("solver returned unrecognized code")
as.character(x)
}

#' Convert to Matrix
#'
#' Convert an object to a matrix class provided by the \pkg{Matrix} package.
#'
#' @param object object.
#'
#' @param class `character` name of new classes.
#'
#' @details
#' This function is a wrapper that is designed to provide
#' compatibility with older and newer versions of the \pkg{Matrix} package.
#'
#' @return `Matrix` object.
#'
#' @noRd
as_Matrix <- function(object, class) {
# assert valid argument
assertthat::assert_that(
assertthat::is.string(class),
assertthat::noNA(class)
)
# if we just want to convert to generic Matrix class then do that...
if (identical(class, "Matrix")) {
return(methods::as(object, class))
}
# convert matrix
if (utils::packageVersion("Matrix") >= as.package_version("1.4-2")) {
if (identical(class, "dgCMatrix")) {
c1 <- "dMatrix"
c2 <- "generalMatrix"
c3 <- "CsparseMatrix"
} else if (identical(class, "dgTMatrix")) {
c1 <- "dMatrix"
c2 <- "generalMatrix"
c3 <- "TsparseMatrix"
} else if (identical(class, "dsCMatrix")) {
c1 <- "dMatrix"
c2 <- "symmetricMatrix"
c3 <- "CsparseMatrix"
} else if (identical(class, "dsTMatrix")) {
c1 <- "dMatrix"
c2 <- "symmetricMatrix"
c3 <- "TsparseMatrix"
} else if (identical(class, "lgCMatrix")) {
c1 <- "lMatrix"
c2 <- "generalMatrix"
c3 <- "CsparseMatrix"
} else {
stop("argument to \"class\" not recognized")
}
out <- methods::as(methods::as(methods::as(object, c1), c2), c3)
} else {
out <- methods::as(object, class)
}
# return result
out
}
4 changes: 2 additions & 2 deletions R/plot_feature_persistence.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ plot_feature_persistence <- function(x, solution, n = 1, symbol_hjust = 0.007,
feature_probs <- rcpp_expected_persistences(
x$pa_matrix(),
x$epf_matrix()[, x$feature_names(), drop = FALSE],
methods::as(diag(x$number_of_features()), "dgCMatrix"),
methods::as(as.matrix(solution), "dgCMatrix"))[1, ]
as_Matrix(diag(x$number_of_features()), "dgCMatrix"),
as_Matrix(as.matrix(solution), "dgCMatrix"))[1, ]

## create plotting data
d <- tibble::tibble(name = x$feature_names(),
Expand Down
Loading

0 comments on commit abc9a6a

Please sign in to comment.