Skip to content

Commit

Permalink
Final fixes for CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
dramanica committed Nov 29, 2022
1 parent 32da7b7 commit 0359763
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 38 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"),
Expand All @@ -11,8 +11,9 @@ Authors@R: c(
email = "[email protected]")
)
Maintainer: Andrea Manica <[email protected]>
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) <doi:10.1101/2022.05.18.492456>.
License: CC BY 4.0
Language: en-GB
URL: https://github.com/EvolEcolGroup/pastclim,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions R/get_data_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
23 changes: 22 additions & 1 deletion R/set_data_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions R/var_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 9 additions & 8 deletions man/get_data_path.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions man/set_data_path_for_CRAN.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/var_labels.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 14 additions & 19 deletions vignettes/a0_pastclim_overview.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -94,37 +94,32 @@ 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:

```{r eval=FALSE}
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).
Expand Down
14 changes: 14 additions & 0 deletions vignettes/a1_available_datasets.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
```

Expand Down
20 changes: 17 additions & 3 deletions vignettes/a2_custom_datasets.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:

Expand Down Expand Up @@ -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.

0 comments on commit 0359763

Please sign in to comment.