Skip to content

prioritizr now supports code vendoring for internal functions - may be of interest? #4

@jeffreyhanson

Description

@jeffreyhanson

Hi,

As part of efforts to make it easier for people to develop packages that build off prioritizr, I've added support for many of prioritizr's internal functions to be easily incorperated into other packages through code vendoring. The idea here is that the source code for these functions can be directly copy-pasted into other packages so that they can use prioritizr's internal fuctions without having to re-implement them - and without prioritizr needing to expose these functions as part of the public API. For example, some of these functions relate to data/parameter validation, handling CRS information from both sf and terra objects, or checking if sf/terra objects spatially overlap.

To use these functions in your own package, you can use the usethis::use_standalone() function to automatically download a file from the prioritizr GitHub repo and store it in your package. This function can also be run to update existing local copies that you have previously made --- meaning that it will be fairly easy to incoerpate any updates to them in the future. In particular, any of the functions in the R source files that start with the standalone- prefix can be used with the usethis::use_standalone() function to make a local copy (e.g., R/standalone-cli.R, R/standalone-asssertions_handlers.R) can be used (see https://github.com/prioritizr/prioritizr/tree/main/R).

For example, the following code could be used to download the R/standalone-asssertions_handlers.R file.

usethis::use_standalone("prioritizr/prioritizr", "R/standalone-asssertions_handlers.R")

Also, the following code could be used to make a local copy all supported files.

# define file names
files  <- c("standalone-all_binary.R", "standalone-all_columns_any_finite.R", 
"standalone-all_columns_inherit.R", "standalone-all_finite.R", 
"standalone-all_positive.R", "standalone-all_proportion.R", "standalone-any_nonNA.R", 
"standalone-any_nonzero.R", "standalone-as_Matrix.R", "standalone-assertions_class.R", 
"standalone-assertions_ConservationProblem.R", "standalone-assertions_functions.R", 
"standalone-assertions_handlers.R", "standalone-assertions_misc.R", 
"standalone-assertions_raster.R", "standalone-assertions_sf.R", 
"standalone-assertions_solvers.R", "standalone-assertions_vector.R", 
"standalone-cli.R", "standalone-get_crs.R", "standalone-is_numeric_values.R", 
"standalone-is_same_crs.R", "standalone-is_spatial_extents_overlap.R", 
"standalone-repr.R")

# make local copy
lapply(files, usethis::use_standalone, repo_spec = "prioritizr/prioritizr")

I just wanted to let you in case this would be useful? Let me know if you have any questions? Also, please feel free to close this issue - I wasn't sure who would be best to email about this, so I figured posting here work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions