prioritizr / prioritizr

Compare eefcf01 ... +4 ... 4b46ae9

Coverage Reach
R/problem.R R/planning_unit_solution_status.R R/eval_replacement_importance.R R/marxan_problem.R R/eval_ferrier_importance.R R/parameters.R R/eval_rare_richness_importance.R R/add_neighbor_contraints.R R/add_cbc_solver.R R/solve.R R/add_linear_penalties.R R/add_feature_contiguity_constraints.R R/add_lpsymphony_solver.R R/presolve_check.R R/add_rsymphony_solver.R R/marxan_boundary_data_to_matrix.R R/add_manual_targets.R R/add_boundary_penalties.R R/add_locked_in_constraints.R R/add_locked_out_constraints.R R/add_manual_locked_constraints.R R/add_manual_bounded_constraints.R R/add_connectivity_penalties.R R/compile.R R/eval_connectivity_summary.R R/boundary_matrix.R R/add_contiguity_constraints.R R/zones.R R/eval_target_coverage_summary.R R/internal.R R/add_shuffle_portfolio.R R/intersecting_units.R R/add_max_phylo_end_objective.R R/add_feature_weights.R R/eval_feature_representation_summary.R R/fast_extract.R R/add_max_phylo_div_objective.R R/add_loglinear_targets.R R/connectivity_matrix.R R/add_absolute_targets.R R/proximity_matrix.R R/add_relative_targets.R R/adjacency_matrix.R R/eval_boundary_summary.R R/rij_matrix.R R/write_problem.R R/predefined_optimization_problem.R R/add_min_largest_shortfall_objective.R R/add_cuts_portfolio.R R/add_max_utility_objective.R R/add_min_shortfall_objective.R R/add_max_features_objective.R R/OptimizationProblem-methods.R R/add_max_cover_objective.R R/pproto.R R/simulate.R R/category_vector.R R/loglinear_interpolation.R R/add_mandatory_allocation_constraints.R R/add_semicontinuous_decisions.R R/feature_abundances.R R/distribute_load.R R/eval_cost_summary.R R/eval_n_summary.R R/binary_stack.R R/add_min_set_objective.R R/run_calculations.R R/add_binary_decisions.R R/add_proportion_decisions.R R/category_layer.R R/Id.R R/branch_matrix.R R/misc.R R/number_of_zones.R R/number_of_features.R R/feature_names.R R/zone_names.R R/number_of_planning_units.R R/tbl_df.R R/number_of_total_units.R R/add_default_objective.R R/targets.R R/add_default_decisions.R R/waiver.R R/new_optimization_problem.R R/add_default_portfolio.R src/rcpp_apply_feature_contiguity_constraints.cpp src/rcpp_boundary_data.cpp src/rcpp_ferrier_score.cpp src/rcpp_apply_contiguity_constraints.cpp src/optimization_problem.cpp src/rcpp_apply_boundary_penalties.cpp src/rcpp_apply_max_phylo_objective.cpp src/rcpp_apply_min_largest_shortfall_objective.cpp src/rcpp_apply_connectivity_penalties.cpp src/rcpp_apply_max_cover_objective.cpp src/rcpp_apply_max_utility_objective.cpp src/rcpp_add_rij_data.cpp src/rcpp_apply_max_features_objective.cpp src/rcpp_apply_min_shortfall_objective.cpp src/rcpp_boundary_data.h src/rcpp_apply_neighbor_constraints.cpp src/rcpp_sp_to_polyset.cpp src/rcpp_boundary.cpp src/rcpp_summarize_exactextractr.cpp src/rcpp_branch_matrix.cpp src/rcpp_absolute_amount_held_by_solution.cpp src/optimization_problem.h src/rcpp_apply_min_set_objective.cpp src/rcpp_str_tree_to_sparse_matrix.cpp src/rcpp_list_to_matrix_indices.cpp src/rcpp_apply_linear_penalties.cpp src/functions.cpp src/rcpp_forbid_solution.cpp src/rcpp_connectivity.cpp src/rcpp_add_zones_constraints.cpp src/rcpp_apply_decisions.cpp src/rcpp_apply_feature_weights.cpp src/rcpp_apply_bounded_constraints.cpp src/rcpp_apply_locked_constraints.cpp src/functions.h src/init.c

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 300 files from the diff.
Other files ignored by Codecov
docs/index.html has changed.
docs/pkgdown.css has changed.
docs/404.html has changed.
docs/authors.html has changed.
docs/pkgdown.js has changed.
README.md has changed.
docs/pkgdown.yml has changed.
NEWS.md has changed.
DESCRIPTION has changed.

@@ -47,9 +47,7 @@
Loading
47 47
#'     with column names that correspond to the abundance or occurrence of
48 48
#'     different features in each planning unit. Note that this argument
49 49
#'     type can only be used to create problems involving a single zone.
50 -
#'   * [`x = Spatial-class`][sp::Spatial-class], or
51 -
#'     [`x = sf::st_sf()`][sf::st_sf()], or
52 -
#'     `x = data.frame`, or
50 +
#'   * `x = data.frame`, or
53 51
#'     `x = numeric` vector, or
54 52
#'     `x = matrix`:
55 53
#'     `y = data.frame` object
@@ -254,27 +252,52 @@
Loading
254 252
#'       add_binary_decisions() %>%
255 253
#'       add_default_solver(verbose = FALSE)
256 254
#'
257 -
#' # add columns to polygon planning unit data representing the abundance
258 -
#' # of species inside them
259 -
#' sim_pu_polygons$spp_1 <- rpois(length(sim_pu_polygons), 5)
260 -
#' sim_pu_polygons$spp_2 <- rpois(length(sim_pu_polygons), 8)
261 -
#' sim_pu_polygons$spp_3 <- rpois(length(sim_pu_polygons), 2)
255 +
#' # since geo-processing can be slow for large spatial vector datasets
256 +
#' # (e.g. polygons, lines, points), it can be worthwhile to pre-process the
257 +
#' # planning unit data so that it contains columns indicating the amount of
258 +
#' # each feature inside each planning unit
259 +
#' # (i.e. each column corresponds to a different feature)
260 +
#'
261 +
#' # calculate the amount of each species within each planning unit
262 +
#' # (i.e. SpatialPolygonsDataFrame object)
263 +
#' pre_proc_data <- rij_matrix(sim_pu_polygons, sim_features)
262 264
#'
263 -
#' # create problem using pre-processed data when feature abundances are
264 -
#' # stored in the columns of an attribute table for a spatial vector dataset
265 -
#' p6 <- problem(sim_pu_polygons, features = c("spp_1", "spp_2", "spp_3"),
266 -
#'               "cost") %>%
265 +
#' # add extra columns to the polygon (Spatial) planning unit data
266 +
#' # to indicate the amount of each species within each planning unit
267 +
#' pre_proc_data <- as.data.frame(t(as.matrix(pre_proc_data)))
268 +
#' names(pre_proc_data) <- names(sim_features)
269 +
#' sim_pu_polygons@data <- cbind(sim_pu_polygons@data, pre_proc_data)
270 +
#'
271 +
#' # create problem using the polygon (Spatial) planning unit data
272 +
#' # with the pre-processed columns
273 +
#' p6 <- problem(sim_pu_polygons, features = names(pre_proc_data), "cost") %>%
267 274
#'       add_min_set_objective() %>%
268 275
#'       add_relative_targets(0.2) %>%
269 276
#'       add_binary_decisions() %>%
270 277
#'       add_default_solver(verbose = FALSE)
271 278
#'
272 -
#' # alternatively one can supply pre-processed aspatial data
279 +
#' # this strategy of pre-processing columns can be used for sf objects too
280 +
#' pre_proc_data2 <- rij_matrix(sim_pu_sf, sim_features)
281 +
#' pre_proc_data2 <- as.data.frame(t(as.matrix(pre_proc_data2)))
282 +
#' names(pre_proc_data2) <- names(sim_features)
283 +
#' sim_pu_sf <- cbind(sim_pu_sf, pre_proc_data2)
284 +
#'
285 +
#' # create problem using the polygon (sf) planning unit data
286 +
#' # with pre-processed columns
287 +
#' p7 <- problem(sim_pu_sf, features = names(pre_proc_data2), "cost") %>%
288 +
#'       add_min_set_objective() %>%
289 +
#'       add_relative_targets(0.2) %>%
290 +
#'       add_binary_decisions() %>%
291 +
#'       add_default_solver(verbose = FALSE)
292 +
#'
293 +
#' # in addition to spatially explicit data, pre-processed aspatial data
294 +
#' # can also be used to create a problem
295 +
#' # (e.g. data created using external spreadsheet software)
273 296
#' costs <- sim_pu_polygons$cost
274 297
#' features <- data.frame(id = seq_len(nlayers(sim_features)),
275 298
#'                        name = names(sim_features))
276 299
#' rij_mat <- rij_matrix(sim_pu_polygons, sim_features)
277 -
#' p7 <- problem(costs, features, rij_matrix = rij_mat) %>%
300 +
#' p8 <- problem(costs, features, rij_matrix = rij_mat) %>%
278 301
#'       add_min_set_objective() %>%
279 302
#'       add_relative_targets(0.2) %>%
280 303
#'       add_binary_decisions() %>%
@@ -288,28 +311,30 @@
Loading
288 311
#' s5 <- solve(p5)
289 312
#' s6 <- solve(p6)
290 313
#' s7 <- solve(p7)
314 +
#' s8 <- solve(p8)
291 315
#'
292 316
#' # plot solutions for problems associated with spatial data
293 317
#' par(mfrow = c(3, 2), mar = c(0, 0, 4.1, 0))
294 -
#' plot(s1, main = "raster data", axes = FALSE, box = FALSE)
318 +
#' plot(s1, main = "raster data", axes = FALSE, box = FALSE, legend = FALSE)
295 319
#'
296 320
#' plot(s2, main = "polygon data")
297 -
#' plot(s2[s2$solution_1 == 1, ], col = "darkgreen", add = TRUE)
321 +
#' plot(s2[s2$solution_1 > 0.5, ], col = "darkgreen", add = TRUE)
298 322
#'
299 323
#' plot(s3, main = "line data")
300 -
#' lines(s3[s3$solution_1 == 1, ], col = "darkgreen", lwd = 2)
324 +
#' lines(s3[s3$solution_1 > 0.5, ], col = "darkgreen", lwd = 2)
301 325
#'
302 326
#' plot(s4, main = "point data", pch = 19)
303 -
#' points(s4[s4$solution_1 == 1, ], col = "darkgreen", cex = 2, pch = 19)
327 +
#' points(s4[s4$solution_1 > 0.5, ], col = "darkgreen", cex = 2, pch = 19)
304 328
#'
305 -
#' plot(s5, main = "sf (polygon) data", pch = 19)
306 -
#' points(s5[s5$solution_1 == 1, ], col = "darkgreen", cex = 2, pch = 19)
329 +
#' # note that as_Spatial() is for convenience to plot all solutions together
330 +
#' plot(as_Spatial(s5), main = "sf (polygon) data", pch = 19)
331 +
#' plot(as_Spatial(s5[s5$solution_1 > 0.5, ]), col = "darkgreen", add = TRUE)
307 332
#'
308 -
#' plot(s6, main = "preprocessed data", pch = 19)
309 -
#' plot(s6[s6$solution_1 == 1, ], col = "darkgreen", add = TRUE)
333 +
#' plot(s6, main = "preprocessed data (polygon data)", pch = 19)
334 +
#' plot(s6[s6$solution_1 > 0.5, ], col = "darkgreen", add = TRUE)
310 335
#'
311 336
#' # show solutions for problems associated with aspatial data
312 -
#' str(s7)
337 +
#' str(s8)
313 338
#' }
314 339
#' # create some problems with multiple zones
315 340
#'

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
R 95.05%
src 98.80%
Project Totals (122 files) 96.22%
Loading