From 03597636b0590eb3219521fc8af7e478b897bbbc Mon Sep 17 00:00:00 2001 From: Andrea Manica Date: Tue, 29 Nov 2022 21:00:23 +0000 Subject: [PATCH] Final fixes for CRAN --- DESCRIPTION | 7 +++--- NAMESPACE | 1 + R/get_data_path.R | 8 +++---- R/set_data_path.R | 23 +++++++++++++++++++- R/var_labels.R | 4 ++++ man/get_data_path.Rd | 17 ++++++++------- man/set_data_path_for_CRAN.Rd | 16 ++++++++++++++ man/var_labels.Rd | 4 ++++ vignettes/a0_pastclim_overview.Rmd | 33 ++++++++++++----------------- vignettes/a1_available_datasets.Rmd | 14 ++++++++++++ vignettes/a2_custom_datasets.Rmd | 20 ++++++++++++++--- 11 files changed, 109 insertions(+), 38 deletions(-) create mode 100644 man/set_data_path_for_CRAN.Rd diff --git a/DESCRIPTION b/DESCRIPTION index c9ecbfa7..2062b6c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: pastclim Type: Package Title: Manipulate Time Series of Palaeoclimate Reconstructions -Version: 1.2.0 +Version: 1.2.1 Authors@R: c( person("Michela", "Leonardi", role = "aut"), person(c("Emily","Y."), "Hallet", role = "ctb"), @@ -11,8 +11,9 @@ Authors@R: c( email = "am315@cam.ac.uk") ) Maintainer: Andrea Manica -Description: This R package is designed to provide an easy way to extract and manipulate palaeoclimate - reconstructions for ecological and anthropological analyses. +Description: Methods to easily extract and manipulate palaeoclimate + reconstructions for ecological and anthropological analyses, as described + in Leonardi et al. (2022) . License: CC BY 4.0 Language: en-GB URL: https://github.com/EvolEcolGroup/pastclim, diff --git a/NAMESPACE b/NAMESPACE index 0ad82c64..35ffae82 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,6 +23,7 @@ export(region_slice) export(sample_region_series) export(sample_region_slice) export(set_data_path) +export(set_data_path_for_CRAN) export(slice_region_series) export(time_bp) export(time_series_for_locations) diff --git a/R/get_data_path.R b/R/get_data_path.R index 42ba530b..fb249268 100644 --- a/R/get_data_path.R +++ b/R/get_data_path.R @@ -25,8 +25,8 @@ get_data_path <- function(silent=FALSE) { "pastclim_data.txt" ))) { if (!silent) { - message("A default data_path was not set for pastclim\n", - "Use `set_data_path()` to set it") + message("A default data_path was not set for pastclim;\n", + "use `set_data_path()` to set it.") } return(NULL) } @@ -35,8 +35,8 @@ get_data_path <- function(silent=FALSE) { "pastclim_data.txt" ))[1, 1] if (!dir.exists(path_to_nc)){ - error("the path ",path_to_nc," from the config file does not exist!\n", - "you can reset the path with `set_data_path`") + stop("The path ",path_to_nc," from the config file does not exist!\n", + "You can reset the path with `set_data_path`.") } return(path_to_nc) } diff --git a/R/set_data_path.R b/R/set_data_path.R index c5fcf5ca..0a5309f9 100644 --- a/R/set_data_path.R +++ b/R/set_data_path.R @@ -43,7 +43,7 @@ set_data_path <- function(path_to_nc = NULL, ask = TRUE, write_config = TRUE, "You will have to reset the path when R is restarted.\n") } message_to_user<-paste0(message_to_user,"Proceed?") - user_choice <- menu(c("Yes","No"), title = message_to_user) + user_choice <- utils::menu(c("Yes","No"), title = message_to_user) } else { # else, if we don't ask, answer yes user_choice <- 1 } @@ -103,3 +103,24 @@ copy_example_data <- function() { return(TRUE) } +#' Set the data path for examples on CRAN +#' +#' Users should NOT need this function. It is used to set up a +#' data path in the temporary directory for examples and tests +#' to run on CRAN. +#' +#' @returns None +#' @export + + +set_data_path_for_CRAN <- function() { + # set up data path for this test + data_path <- file.path(tempdir(),"pastclim_data") + # clear it if it exists + unlink(data_path, recursive = TRUE) + # set data path + set_data_path(path_to_nc = data_path, + ask = FALSE, + write_config = FALSE, + copy_example = TRUE) +} diff --git a/R/var_labels.R b/R/var_labels.R index 4bf2cb6a..b4692816 100644 --- a/R/var_labels.R +++ b/R/var_labels.R @@ -17,6 +17,10 @@ #' @examples #' var_labels("bio01", dataset = "Example") #' +#' # set the data_path for this example to run on CRAN +#' # users don't need to run this line +#' set_data_path_for_CRAN() +#' #' # for a SpatRaster #' climate_20k <- region_slice( #' time_bp = -20000, diff --git a/man/get_data_path.Rd b/man/get_data_path.Rd index e92db97c..535ec4ae 100644 --- a/man/get_data_path.Rd +++ b/man/get_data_path.Rd @@ -4,21 +4,22 @@ \alias{get_data_path} \title{Get the data path where climate reconstructions are stored} \usage{ -get_data_path() +get_data_path(silent = FALSE) +} +\arguments{ +\item{silent}{boolean on whether a message is returned when data_path is +not set (i.e. equal to NULL)} } \value{ the data path } \description{ -This function returns the path where climate reconstructions will be stored. -When `pastclim` is installed, the data path defaults to the directory -returned by `tools::R_user_dir("pastclim","data")` (i.e. the data directory -for the package in R>=4.0). The data path can be changed with -\code{set_data_path}. Once changed, `pastclim` will remember the new data -path in the future. +This function returns the path where climate reconstructions are stored. } \details{ -The data path is stored in a file named "pastclim_data.txt", which +The path is stored in an option for `pastclim` named `data_path`. If +a configuration file was saved when using \code{set_data_path}, the path +is retrived from a file named "pastclim_data.txt", which is found in the directory returned by `tools::R_user_dir("pastclim","config")` (i.e. the default configuration directory for the package as set in R >= 4.0). diff --git a/man/set_data_path_for_CRAN.Rd b/man/set_data_path_for_CRAN.Rd new file mode 100644 index 00000000..5d2ba6fa --- /dev/null +++ b/man/set_data_path_for_CRAN.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/set_data_path.R +\name{set_data_path_for_CRAN} +\alias{set_data_path_for_CRAN} +\title{Set the data path for examples on CRAN} +\usage{ +set_data_path_for_CRAN() +} +\value{ +None +} +\description{ +Users should NOT need this function. It is used to set up a +data path in the temporary directory for examples and tests +to run on CRAN. +} diff --git a/man/var_labels.Rd b/man/var_labels.Rd index 0fa661bb..44aad940 100644 --- a/man/var_labels.Rd +++ b/man/var_labels.Rd @@ -29,6 +29,10 @@ for plotting \examples{ var_labels("bio01", dataset = "Example") +# set the data_path for this example to run on CRAN +# users don't need to run this line +set_data_path_for_CRAN() + # for a SpatRaster climate_20k <- region_slice( time_bp = -20000, diff --git a/vignettes/a0_pastclim_overview.Rmd b/vignettes/a0_pastclim_overview.Rmd index 691e65eb..e322b807 100644 --- a/vignettes/a0_pastclim_overview.Rmd +++ b/vignettes/a0_pastclim_overview.Rmd @@ -94,27 +94,25 @@ library(pastclim) set_data_path() ``` -```{r echo=FALSE} -data_path <- file.path(tempdir(),"pastclim_data") -unlink(data_path, recursive = TRUE) # it should not exist, but remove it just in case -# set data path -set_data_path(path_to_nc = data_path, - ask = FALSE, - write_config = FALSE, - copy_example = TRUE) +```{r echo=FALSE, results='hide'} +library(pastclim) +set_data_path_for_CRAN() ``` - ``` -The data_path will be set to /home/am315/.local/share/R/pastclim. -A copy of the Example dataset will be copied there. -This path will be saved by pastclim for future use. -Proceed? - -1: Yes -2: No +#> The data_path will be set to /home/andrea/.local/share/R/pastclim. +#> A copy of the Example dataset will be copied there. +#> This path will be saved by pastclim for future use. +#> Proceed? +#> +#> 1: Yes +#> 2: No ``` +Press 1 if you are happy with the offered choices, and `pastclim` +will remember your data path in future sessions. Note that your +data path will look different than in this example, as it depends +on your user name and operating system. If you prefer using a custom path (e.g. in "~/my_reconstructions"), it can be set with: @@ -122,9 +120,6 @@ If you prefer using a custom path (e.g. in "~/my_reconstructions"), it can be se set_data_path(path_to_nc = "~/my_reconstructions") ``` -`pastclim` will remember this new path in the future, even after closing and restarting -R. - The package includes a small dataset, *Example*, that we will use in this vignette but is not suitable for running analyses; the real datasets are large (from 100s of Mb to a few Gb), and you will need to specify what you want to download (see below). diff --git a/vignettes/a1_available_datasets.Rmd b/vignettes/a1_available_datasets.Rmd index 03525a48..e3401aa9 100644 --- a/vignettes/a1_available_datasets.Rmd +++ b/vignettes/a1_available_datasets.Rmd @@ -21,6 +21,20 @@ A number of datasets are available in pastclim. It is possible to use custom dat ```{r} library(pastclim) +``` + +```{r echo=FALSE, results='hide'} +data_path <- file.path(tempdir(),"pastclim_data") +# clear it in case it exists already +unlink(data_path, recursive = TRUE) +# set data path +set_data_path(path_to_nc = data_path, + ask = FALSE, + write_config = FALSE, + copy_example = TRUE) +``` + +```{r} get_available_datasets() ``` diff --git a/vignettes/a2_custom_datasets.Rmd b/vignettes/a2_custom_datasets.Rmd index e1d055f5..7d8feee1 100644 --- a/vignettes/a2_custom_datasets.Rmd +++ b/vignettes/a2_custom_datasets.Rmd @@ -65,9 +65,23 @@ ncdf4::nc_close(nc_in) ``` -We can now read in our custom netcdf file. +We can now read in our custom netcdf file with `pastclim`. ```{r} library(pastclim) +``` + +```{r echo=FALSE, results='hide'} +data_path <- file.path(tempdir(),"pastclim_data") +# clear it in case it exists already +unlink(data_path, recursive = TRUE) +# set data path +set_data_path(path_to_nc = data_path, + ask = FALSE, + write_config = FALSE, + copy_example = TRUE) +``` + +```{r} custom_series <- region_series(bio_variables = "bio01", dataset = "custom", path_to_nc = nc_name @@ -92,7 +106,7 @@ it allows for smaller files). # Making the data available to others -Once you have created suitably fomatted netcdf files that can be used as custom datasets in +Once you have created suitably formatted netcdf files that can be used as custom datasets in `pastclim`, you can add those data officially to the package, and thus make them available to others. Here are the necessary steps: @@ -142,6 +156,6 @@ the *nc* dataset. 3) Once you have added lines detailing the variables in your dataset, run the script "./inst/rawdata_scripts/create_files_by_dataset.R" to store that information into the appropriate dataset in `pastclim`. -4) Provide information on the new dataset in the file "./R/dataset_docs", using `roxygen2` notation. Make sure that you provide an appropriate reference for the original data, as it is important that users can refer back to the original source. +4) Provide information on the new dataset in the file "./R/dataset_docs", using `roxygen2` syntax. Make sure that you provide an appropriate reference for the original data, as it is important that users can refer back to the original source. 4) Make a Pull Request on GitHub. \ No newline at end of file