diff --git a/DESCRIPTION b/DESCRIPTION index 9ade51e0..e24976dc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: mapme.biodiversity Title: Efficient Monitoring of Global Biodiversity Portfolios -Version: 0.0.1 +Version: 0.1.0 Authors@R: c( person("Darius A.", "Görgen", , "darius2402@web.de", role = c("aut", "cre")), person("Om Prakash", "Bhandari", role = "aut") diff --git a/NEWS.md b/NEWS.md index 4603410e..d15c1992 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,27 @@ +# mapme.biodiversity (development version) + +## Breaking changes + +## New features + +## Internal + +# mapme.biodiversity 0.1.0 + +## Breaking changes +* renamed '.assetid' to 'assetid' (#22) + +## New features +* None + +## Internal +* ensured that tests and examples adhere to CRAN policies of +only writing to the temporal directory (#22) + # mapme.biodiversity 0.0.1 +## Initial release + * Added a `NEWS.md` file to track changes to the package. * initial supported resources are: - ecoregions @@ -45,6 +67,8 @@ * on MacOS, the s2 engine for spherical geometric vector operations is disabled and lwgeom is used instead. -* Introduced absolute URLS in userguide.Rmd pointing to the online documentation (#58) -* \value tags added to all exported functions explaining what is the output/sideffect (#58) +## Internal + +* Introduced absolute URLS in userguide.Rmd pointing to the online documentation (#59) +* \value tags added to all exported functions explaining what is the output/sideffect (#59) * using requireNamespace() instead of installed.packages() to check if packages listed in SUGGEST are loadable (#58) diff --git a/R/calc_accessibility.R b/R/calc_accessibility.R index 9ffb9981..03e146c6 100644 --- a/R/calc_accessibility.R +++ b/R/calc_accessibility.R @@ -23,12 +23,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2022, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_biome.R b/R/calc_biome.R index 7cd91ae6..b6fc16e1 100644 --- a/R/calc_biome.R +++ b/R/calc_biome.R @@ -14,12 +14,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2001, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_chirpsprec.R b/R/calc_chirpsprec.R index 8d196b22..301a2ffb 100644 --- a/R/calc_chirpsprec.R +++ b/R/calc_chirpsprec.R @@ -28,12 +28,20 @@ #' if(Sys.getenv("NOT_CRAN") == "true"){ #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2010, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' cores = 1, #' verbose = FALSE #' ) %>% diff --git a/R/calc_drought_indicator.R b/R/calc_drought_indicator.R index fde1a6c9..d4ef46a1 100644 --- a/R/calc_drought_indicator.R +++ b/R/calc_drought_indicator.R @@ -23,12 +23,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2022, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_elevation.R b/R/calc_elevation.R index bc615365..3a1af722 100644 --- a/R/calc_elevation.R +++ b/R/calc_elevation.R @@ -22,12 +22,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2000:2020, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_emissions.R b/R/calc_emissions.R index 2ba690ef..3180ac3b 100644 --- a/R/calc_emissions.R +++ b/R/calc_emissions.R @@ -23,12 +23,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2016:2017, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_gmw.R b/R/calc_gmw.R index 8d7873a3..44f977f0 100644 --- a/R/calc_gmw.R +++ b/R/calc_gmw.R @@ -14,14 +14,22 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "shell_beach_protected_area_41057_B.gpkg", #' package = "mapme.biodiversity" #' ) %>% #' read_sf() %>% #' init_portfolio( #' years = c(1996, 2016), -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_landcover.R b/R/calc_landcover.R index c4e824a2..589d7f89 100644 --- a/R/calc_landcover.R +++ b/R/calc_landcover.R @@ -16,12 +16,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2016:2017, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_popcount.R b/R/calc_popcount.R index f3dcd4ed..b890c962 100644 --- a/R/calc_popcount.R +++ b/R/calc_popcount.R @@ -25,12 +25,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2000:2010, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_soilproperties.R b/R/calc_soilproperties.R index 8f50090d..e294baa7 100644 --- a/R/calc_soilproperties.R +++ b/R/calc_soilproperties.R @@ -26,12 +26,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2022, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_teow.R b/R/calc_teow.R index 1e309caa..b488fe84 100644 --- a/R/calc_teow.R +++ b/R/calc_teow.R @@ -14,12 +14,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2001, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_treecover.R b/R/calc_treecover.R index 8afa3b12..ec34c2be 100644 --- a/R/calc_treecover.R +++ b/R/calc_treecover.R @@ -21,12 +21,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2016:2017, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_treeloss.R b/R/calc_treeloss.R index 1ca1b945..569b2fcb 100644 --- a/R/calc_treeloss.R +++ b/R/calc_treeloss.R @@ -23,12 +23,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2016:2017, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_tri.R b/R/calc_tri.R index 9edbecba..e19269f7 100644 --- a/R/calc_tri.R +++ b/R/calc_tri.R @@ -35,12 +35,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2000:2020, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_wcprec.R b/R/calc_wcprec.R index 0c36c764..463563ec 100644 --- a/R/calc_wcprec.R +++ b/R/calc_wcprec.R @@ -22,12 +22,21 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2018, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_wctmax.R b/R/calc_wctmax.R index 404b55e4..46252444 100644 --- a/R/calc_wctmax.R +++ b/R/calc_wctmax.R @@ -22,12 +22,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2018, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/calc_wctmin.R b/R/calc_wctmin.R index cc8b44ba..99c1e6b5 100644 --- a/R/calc_wctmin.R +++ b/R/calc_wctmin.R @@ -22,12 +22,20 @@ #' @examples #' library(sf) #' library(mapme.biodiversity) +#' +#' temp_loc <- file.path(tempdir(), "mapme.biodiversity") +#' if(!file.exists(temp_loc)){ +#' dir.create(temp_loc) +#' resource_dir <- system.file("res", package = "mapme.biodiversity") +#' file.copy(resource_dir, temp_loc, recursive = TRUE) +#' } +#' #' (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% #' read_sf() %>% #' init_portfolio( #' years = 2018, -#' outdir = system.file("res", package = "mapme.biodiversity"), -#' tmpdir = system.file("tmp", package = "mapme.biodiversity"), +#' outdir = file.path(temp_loc, "res"), +#' tmpdir = tempdir(), #' add_resources = FALSE, #' cores = 1, #' verbose = FALSE diff --git a/R/portfolio.R b/R/portfolio.R index 539b4cdc..044cbba4 100644 --- a/R/portfolio.R +++ b/R/portfolio.R @@ -88,15 +88,15 @@ init_portfolio <- function(x, stop("Some assests are not of type POLYGON. Please use sf::st_cast() to cast to POLYGON.") } # add a unique asset identifier - if (".assetid" %in% names(x)) { + if ("assetid" %in% names(x)) { message( - paste("Found a column named '.assetid'. ", - "Overwritting its values with a unique identifier.", + paste("Found a column named 'assetid'.", + " Overwritting its values with a unique identifier.", sep = "" ) ) } - x$.assetid <- 1:nrow(x) + x$assetid <- 1:nrow(x) # check if resources already exist resources <- list() @@ -136,7 +136,7 @@ init_portfolio <- function(x, #' to a table called 'metadata'. All available and supported indicators, which #' are expected to be present as a nested list columns will be written to their #' own respective tables. In order to allow re-joining the metadata with the -#' indicators, it is expected that a column called '.assetid' which uniquely +#' indicators, it is expected that a column called 'assetid' which uniquely #' identifies all assets is present. Usually, users do not have to take care of #' this since the usual \code{{mapme.biodiversity}} workflow will ensure that this #' columns is present. Additional arguments to \code{st_write()} can be supplied. @@ -153,7 +153,7 @@ write_portfolio <- function(x, dsn, overwrite = FALSE, ...) { - .assetid <- NULL + assetid <- NULL all_indicators <- names(available_indicators()) present_indicators <- names(x)[which(names(x) %in% all_indicators)] @@ -179,24 +179,24 @@ write_portfolio <- function(x, present_indicators <- present_indicators[-index] } - if (!".assetid" %in% names(x)) { - stop("Column '.assetid' is missing.") + if (!"assetid" %in% names(x)) { + stop("Column 'assetid' is missing.") } - if (nrow(x) != length(unique(x$.assetid))) { - stop("Column '.assetid' does not uniquley identify assets.") + if (nrow(x) != length(unique(x$assetid))) { + stop("Column 'assetid' does not uniquley identify assets.") } # separate metadata from data metadata <- dplyr::select(x, -tidyselect::all_of(present_indicators)) - data <- st_drop_geometry(dplyr::select(x, .assetid, tidyselect::all_of(present_indicators))) + data <- st_drop_geometry(dplyr::select(x, assetid, tidyselect::all_of(present_indicators))) # initiate GPKG with metadata (including geometries) st_write(metadata, dsn, "metadata", delete_dsn = overwrite, ...) # loop through the nested indicators and append as their own layers for (ind in present_indicators) { - tmp <- dplyr::select(data, .assetid, tidyselect::all_of(ind)) + tmp <- dplyr::select(data, assetid, tidyselect::all_of(ind)) tmp <- tidyr::unnest(tmp, tidyselect::all_of(ind)) st_write(tmp, dsn, ind, append = TRUE, ...) } @@ -230,7 +230,7 @@ write_portfolio <- function(x, #' @export #' read_portfolio <- function(file, ...) { - .assetid <- NULL + assetid <- NULL all_layers <- st_layers(file) if (!"metadata" %in% all_layers$name | all_layers$geomtype[[which(all_layers$name == "metadata")]] != "Polygon") { stop(sprintf( @@ -247,9 +247,9 @@ read_portfolio <- function(file, ...) { for (ind in present_indicators) { tmp <- read_sf(file, layer = ind, ...) - tmp <- tidyr::nest(tmp, data = !.assetid) + tmp <- tidyr::nest(tmp, data = !assetid) names(tmp)[2] <- ind - metadata <- dplyr::left_join(metadata, tmp, by = ".assetid") + metadata <- dplyr::left_join(metadata, tmp, by = "assetid") } dplyr::relocate(metadata, !!attributes(metadata)[["sf_column"]], .after = tidyselect::last_col()) diff --git a/man/accessibility.Rd b/man/accessibility.Rd index ec1c2720..64d5f4cd 100644 --- a/man/accessibility.Rd +++ b/man/accessibility.Rd @@ -30,12 +30,20 @@ one or multiple inputs as character. Supported statistics are: "mean", \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2022, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/biome.Rd b/man/biome.Rd index dce19783..72e17b35 100644 --- a/man/biome.Rd +++ b/man/biome.Rd @@ -20,12 +20,20 @@ The required resources for this indicator are: \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2001, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/chirpsprec.Rd b/man/chirpsprec.Rd index 57597f62..2ac4e4d2 100644 --- a/man/chirpsprec.Rd +++ b/man/chirpsprec.Rd @@ -35,12 +35,20 @@ order to fit the SPI. Defaults to 8 years.} if(Sys.getenv("NOT_CRAN") == "true"){ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2010, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), cores = 1, verbose = FALSE ) \%>\% diff --git a/man/drought_indicator.Rd b/man/drought_indicator.Rd index 921eda48..8e80ebca 100644 --- a/man/drought_indicator.Rd +++ b/man/drought_indicator.Rd @@ -30,12 +30,20 @@ one or multiple inputs as character "mean", "median" or "sd".} \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2022, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/elevation.Rd b/man/elevation.Rd index 086821d7..e0b66a14 100644 --- a/man/elevation.Rd +++ b/man/elevation.Rd @@ -29,12 +29,20 @@ one or multiple inputs as character. Supported statistics are: "mean", \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2000:2020, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/emissions.Rd b/man/emissions.Rd index 3794fcca..f3f32771 100644 --- a/man/emissions.Rd +++ b/man/emissions.Rd @@ -30,12 +30,20 @@ The following arguments can be set: \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2016:2017, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/gmw.Rd b/man/gmw.Rd index 98fbdaed..a1e6625f 100644 --- a/man/gmw.Rd +++ b/man/gmw.Rd @@ -20,14 +20,22 @@ The required resources for this indicator are: \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "shell_beach_protected_area_41057_B.gpkg", package = "mapme.biodiversity" ) \%>\% read_sf() \%>\% init_portfolio( years = c(1996, 2016), - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/landcover.Rd b/man/landcover.Rd index e63829d5..2e83a298 100644 --- a/man/landcover.Rd +++ b/man/landcover.Rd @@ -22,12 +22,20 @@ The required resources for this indicator are: \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2016:2017, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/popcount.Rd b/man/popcount.Rd index ddd121f4..57c20bc2 100644 --- a/man/popcount.Rd +++ b/man/popcount.Rd @@ -32,12 +32,20 @@ one or multiple inputs as character. Supported statistics are: "mean", \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2000:2010, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/soilproperties.Rd b/man/soilproperties.Rd index 17553c5b..ee8081e3 100644 --- a/man/soilproperties.Rd +++ b/man/soilproperties.Rd @@ -33,12 +33,20 @@ single or multiple inputs as character. Supported statistics are: "mean", \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2022, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/teow.Rd b/man/teow.Rd index aa5edac7..356fda32 100644 --- a/man/teow.Rd +++ b/man/teow.Rd @@ -20,12 +20,20 @@ The required resources for this indicator are: \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2001, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/treecover.Rd b/man/treecover.Rd index e28e0f56..105880df 100644 --- a/man/treecover.Rd +++ b/man/treecover.Rd @@ -28,12 +28,20 @@ The following arguments can be set: \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2016:2017, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/treeloss.Rd b/man/treeloss.Rd index 8369b68f..4adb73b1 100644 --- a/man/treeloss.Rd +++ b/man/treeloss.Rd @@ -30,12 +30,20 @@ The following arguments can be set: \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2016:2017, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/tri.Rd b/man/tri.Rd index f5438d37..8253a68c 100644 --- a/man/tri.Rd +++ b/man/tri.Rd @@ -40,12 +40,20 @@ single or multiple inputs as character. Supported statistics are: "mean", \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2000:2020, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/wcprec.Rd b/man/wcprec.Rd index 3dc6cb05..47e42857 100644 --- a/man/wcprec.Rd +++ b/man/wcprec.Rd @@ -29,12 +29,21 @@ one or multiple inputs as character. Supported statistics are: "mean", \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2018, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/wctmax.Rd b/man/wctmax.Rd index 609bea1f..6f962d3c 100644 --- a/man/wctmax.Rd +++ b/man/wctmax.Rd @@ -29,12 +29,20 @@ one or multiple inputs as character. Supported statistics are: "mean", \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2018, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/wctmin.Rd b/man/wctmin.Rd index e05e368b..dba0e7ef 100644 --- a/man/wctmin.Rd +++ b/man/wctmin.Rd @@ -29,12 +29,20 @@ one or multiple inputs as character. Supported statistics are: "mean", \examples{ library(sf) library(mapme.biodiversity) + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +if(!file.exists(temp_loc)){ +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) +} + (aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") \%>\% read_sf() \%>\% init_portfolio( years = 2018, - outdir = system.file("res", package = "mapme.biodiversity"), - tmpdir = system.file("tmp", package = "mapme.biodiversity"), + outdir = file.path(temp_loc, "res"), + tmpdir = tempdir(), add_resources = FALSE, cores = 1, verbose = FALSE diff --git a/man/write_portfolio.Rd b/man/write_portfolio.Rd index 22a6efa7..b8591933 100644 --- a/man/write_portfolio.Rd +++ b/man/write_portfolio.Rd @@ -28,7 +28,7 @@ The metadata of a portfolio together with the geometry will be written to a table called 'metadata'. All available and supported indicators, which are expected to be present as a nested list columns will be written to their own respective tables. In order to allow re-joining the metadata with the -indicators, it is expected that a column called '.assetid' which uniquely +indicators, it is expected that a column called 'assetid' which uniquely identifies all assets is present. Usually, users do not have to take care of this since the usual \code{{mapme.biodiversity}} workflow will ensure that this columns is present. Additional arguments to \code{st_write()} can be supplied. diff --git a/tests/testthat.R b/tests/testthat.R index 6048016d..49ea1c22 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -3,4 +3,12 @@ library(mapme.biodiversity) library(pbapply) pboptions(type = "none") + +temp_loc <- file.path(tempdir(), "mapme.biodiversity") +dir.create(temp_loc) +resource_dir <- system.file("res", package = "mapme.biodiversity") +file.copy(resource_dir, temp_loc, recursive = TRUE) + test_check("mapme.biodiversity") + +unlink(temp_loc, recursive = TRUE, force = TRUE) diff --git a/tests/testthat/_snaps/portfolio.md b/tests/testthat/_snaps/portfolio.md index 3f594969..45a15288 100644 --- a/tests/testthat/_snaps/portfolio.md +++ b/tests/testthat/_snaps/portfolio.md @@ -20,7 +20,7 @@ Bounding box: xmin: -71.80933 ymin: 18.57668 xmax: -71.33201 ymax: 18.69931 Geodetic CRS: WGS 84 # A tibble: 1 x 7 - WDPAID NAME DESIG_ENG ISO3 .assetid chirpsprec geom - - 1 478140 Sierra d~ National~ DOM 1 ((-71.76134 18.66333, -7~ + WDPAID NAME DESIG_ENG ISO3 assetid chirpsprec geom + + 1 478140 Sierra de~ National~ DOM 1 ((-71.76134 18.66333, -7~ diff --git a/tests/testthat/test-get_SRTMdem.R b/tests/testthat/test-get_SRTMdem.R index e1056c5c..4aa2f6d4 100644 --- a/tests/testthat/test-get_SRTMdem.R +++ b/tests/testthat/test-get_SRTMdem.R @@ -6,12 +6,8 @@ test_that(".get_srtm works", { ) aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON")[1, ]) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() portfolio <- init_portfolio(aoi, years = 2000:2020, diff --git a/tests/testthat/test-get_accessibility.R b/tests/testthat/test-get_accessibility.R index 562833b9..57bc380e 100644 --- a/tests/testthat/test-get_accessibility.R +++ b/tests/testthat/test-get_accessibility.R @@ -6,12 +6,8 @@ test_that(".get_worldpop works", { ) aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON")[1, ]) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() portfolio <- init_portfolio(aoi, years = 2000:2020, diff --git a/tests/testthat/test-get_chirps.R b/tests/testthat/test-get_chirps.R index bded2a08..ec4117f2 100644 --- a/tests/testthat/test-get_chirps.R +++ b/tests/testthat/test-get_chirps.R @@ -6,12 +6,8 @@ test_that(".get_worldpop works", { ) aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON")[1, ]) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() portfolio <- init_portfolio(aoi, years = 2000:2020, diff --git a/tests/testthat/test-get_climaticVariables.R b/tests/testthat/test-get_climaticVariables.R index cd595318..18ed8b73 100644 --- a/tests/testthat/test-get_climaticVariables.R +++ b/tests/testthat/test-get_climaticVariables.R @@ -6,12 +6,8 @@ test_that(".get_worldpop works", { ) aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON")[1, ]) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() portfolio <- init_portfolio(aoi, years = 2000:2020, diff --git a/tests/testthat/test-get_droughtInd.R b/tests/testthat/test-get_droughtInd.R index 462060da..e31d794b 100644 --- a/tests/testthat/test-get_droughtInd.R +++ b/tests/testthat/test-get_droughtInd.R @@ -6,12 +6,8 @@ test_that(".get_droughtind works", { ) aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON")[1, ]) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() portfolio <- init_portfolio(aoi, years = 2000:2020, diff --git a/tests/testthat/test-get_esalandcover.R b/tests/testthat/test-get_esalandcover.R index 3fa8120f..a6ff4fe1 100644 --- a/tests/testthat/test-get_esalandcover.R +++ b/tests/testthat/test-get_esalandcover.R @@ -6,12 +6,8 @@ test_that(".get_esalandcover works", { ) aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON")[1, ]) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() portfolio <- init_portfolio(aoi, years = 2000:2020, diff --git a/tests/testthat/test-get_greenhouse.R b/tests/testthat/test-get_greenhouse.R index 7cb76685..74456108 100644 --- a/tests/testthat/test-get_greenhouse.R +++ b/tests/testthat/test-get_greenhouse.R @@ -6,12 +6,8 @@ test_that(".get_greenhouse works", { ) aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON")[1, ]) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() portfolio <- init_portfolio(aoi, years = 2000:2020, diff --git a/tests/testthat/test-get_lossyear.R b/tests/testthat/test-get_lossyear.R index 481090a2..6b319362 100644 --- a/tests/testthat/test-get_lossyear.R +++ b/tests/testthat/test-get_lossyear.R @@ -6,12 +6,8 @@ test_that(".get_lossyear works", { ) aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON")[1, ]) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() portfolio <- init_portfolio(aoi, years = 2000:2020, diff --git a/tests/testthat/test-get_mangrove.R b/tests/testthat/test-get_mangrove.R index 3fa5780e..558e7cbe 100644 --- a/tests/testthat/test-get_mangrove.R +++ b/tests/testthat/test-get_mangrove.R @@ -6,12 +6,8 @@ test_that(".get_mangrove works", { ) aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON")[1, ]) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() portfolio <- init_portfolio(aoi, years = 2000:2020, diff --git a/tests/testthat/test-get_resources.R b/tests/testthat/test-get_resources.R index 736f544e..9ee85fe2 100644 --- a/tests/testthat/test-get_resources.R +++ b/tests/testthat/test-get_resources.R @@ -5,12 +5,8 @@ test_that("get_resources works", { ) ) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON"))[1, ] portfolio <- init_portfolio(aoi, diff --git a/tests/testthat/test-get_soilgrids.R b/tests/testthat/test-get_soilgrids.R index 23a261ad..34d4778a 100644 --- a/tests/testthat/test-get_soilgrids.R +++ b/tests/testthat/test-get_soilgrids.R @@ -6,12 +6,8 @@ test_that("get_soilgrids works", { ) aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON")[1, ]) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() portfolio <- init_portfolio(aoi, years = 2000:2020, diff --git a/tests/testthat/test-get_treecover.R b/tests/testthat/test-get_treecover.R index c2db75f3..0fdaff4b 100644 --- a/tests/testthat/test-get_treecover.R +++ b/tests/testthat/test-get_treecover.R @@ -6,12 +6,8 @@ test_that(".get_treecover works", { ) aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON")[1, ]) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() portfolio <- init_portfolio(aoi, years = 2000:2020, diff --git a/tests/testthat/test-get_worldpop.R b/tests/testthat/test-get_worldpop.R index d2b3774c..166d5c90 100644 --- a/tests/testthat/test-get_worldpop.R +++ b/tests/testthat/test-get_worldpop.R @@ -6,12 +6,8 @@ test_that(".get_worldpop works", { ) aoi <- suppressWarnings(st_cast(aoi, to = "POLYGON")[1, ]) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() portfolio <- init_portfolio(aoi, years = 2001, diff --git a/tests/testthat/test-portfolio.R b/tests/testthat/test-portfolio.R index 5768d7ca..e29f963f 100644 --- a/tests/testthat/test-portfolio.R +++ b/tests/testthat/test-portfolio.R @@ -5,12 +5,8 @@ test_that("init_portfolio works", { ) ) - outdir <- system.file("res", - package = "mapme.biodiversity" - ) - tmpdir <- system.file("tmp", - package = "mapme.biodiversity" - ) + outdir <- file.path(tempdir(), "mapme.biodiversity", "res") + tmpdir <- tempdir() cores <- ifelse(Sys.info()["sysname"] == "Windows", 1, 2) @@ -54,7 +50,7 @@ test_that("init_portfolio works", { cores = cores, verbose = TRUE ), - "'.assetid'. Overwritting its values with a unique identifier." + "'assetid'. Overwritting its values with a unique identifier." ) aoi2 <- st_transform(aoi, st_crs(3857)) diff --git a/vignettes/terminology.Rmd b/vignettes/terminology.Rmd index 47710856..42b0a9ac 100644 --- a/vignettes/terminology.Rmd +++ b/vignettes/terminology.Rmd @@ -36,7 +36,7 @@ In case the CRS of the portfolio is projected, we will attempt to transform to EPSG:4326. Any metadata that is needed for your analysis is allowed in the columns of the object and will be retained throughout the workflow so that you can access it once you have calculated your indicators. -The package will add a unique asset identifier called .assetid and +The package will add a unique asset identifier called assetid and add *nested list columns* for each indicator. Portfolio-wide arguments are set as attributes during the call of init_portfolio(). Except from these additional arguments, an portfolio object actually is and will behave as a familiar {sf} diff --git a/vignettes/userguide.Rmd b/vignettes/userguide.Rmd index cdc643f2..317c4337 100644 --- a/vignettes/userguide.Rmd +++ b/vignettes/userguide.Rmd @@ -97,7 +97,7 @@ aoi_gridded[metanames] <- st_drop_geometry(aoi) Now, we are ready to initiate a portfolio object containing multiple assets. We use the init_portfolio() function and set some attributes that are important for the subsequent processing. The function will add a unique -identifier column called `.assetid` that is used to uniquely identify each +identifier column called 'assetid' that is used to uniquely identify each asset in the portfolio. ```{r init_portfolio, dpi = 50, out.width="120%", out.height="120%"} @@ -110,7 +110,7 @@ sample_portfolio <- init_portfolio( cores = 1, verbose = TRUE ) -plot(sample_portfolio[".assetid"]) +plot(sample_portfolio["assetid"]) ``` The first argument, `x`, is the sf-object that we want to turn into a portfolio. @@ -245,7 +245,7 @@ Now let's take a look at the results. We will select only some of the metadata and the output indicator column to get a clearer picture of what has happened. ```{r select_cols} -(sample_portfolio <- sample_portfolio %>% select(.assetid, WDPAID, chirpsprec)) +(sample_portfolio <- sample_portfolio %>% select(assetid, WDPAID, chirpsprec)) ``` We obtained a new listed column in our sf object that is called like the requested @@ -265,7 +265,7 @@ Let's quickly visualize the results for a single asset: ```{r plot_precipitation, echo = FALSE, warning=FALSE, dpi = 50} sample_portfolio %>% - filter(.assetid == 10) %>% + filter(assetid == 10) %>% st_drop_geometry() %>% tidyr::unnest(chirpsprec) %>% mutate(sign = ifelse(anomaly < 0, "lower than average", "higher than average")) %>% @@ -280,7 +280,7 @@ sample_portfolio %>% theme(legend.position = "bottom") sample_portfolio %>% - filter(.assetid == 10) %>% + filter(assetid == 10) %>% st_drop_geometry() %>% tidyr::unnest(chirpsprec) %>% mutate( @@ -298,7 +298,7 @@ sample_portfolio %>% theme(legend.position = "bottom") sample_portfolio %>% - filter(.assetid == 10) %>% + filter(assetid == 10) %>% st_drop_geometry() %>% tidyr::unnest(chirpsprec) %>% ggplot() + @@ -313,11 +313,11 @@ a good idea to keep the geometry information in a separated variable to keep the size of the data object relatively small. ```{r unnest} -geometries <- select(sample_portfolio, .assetid) +geometries <- select(sample_portfolio, assetid) sample_portfolio %>% st_drop_geometry() %>% tidyr::unnest(chirpsprec) %>% - filter(.assetid == 3) + filter(assetid == 3) ``` # Exporting an portfolio object