Skip to content

Commit

Permalink
Merge branch 'cran_submission'
Browse files Browse the repository at this point in the history
  • Loading branch information
dramanica committed Apr 26, 2023
2 parents 393ff33 + 46a2b2e commit d5d7427
Show file tree
Hide file tree
Showing 94 changed files with 1,048 additions and 746 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [master, dev]
branches: [master, dev, cran_submission]
pull_request:
branches: [master, dev]

Expand Down Expand Up @@ -43,11 +43,11 @@ jobs:
with:
extra-packages: any::rcmdcheck
needs: check
- name: Get dev terra for MacOS
if: matrix.config.os == 'macos-latest'
run: install.packages('terra', repos='https://rspatial.r-universe.dev')
shell: Rscript {0}

# - name: Get dev terra for dev pastclim
# if: matrix.config.os == 'macos-latest' || ${{ github.base_ref == 'dev' }} || ${{ github.ref_name == 'dev' }}
# run: install.packages('terra', repos='https://rspatial.r-universe.dev')
# shell: Rscript {0}

- uses: r-lib/actions/check-r-package@v2
with:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ jobs:
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Get dev terra for dev pastclim
if: ${{ github.base_ref == 'dev' }} || ${{ github.ref_name == 'dev' }}
run: install.packages('terra', repos='https://rspatial.r-universe.dev')
shell: Rscript {0}

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
Expand Down
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 1.2.3
Date: 2022-12-16 08:38:38 UTC
SHA: 81c730879176e3ceecabce36f4cadb05d4286291
Version: 1.2.4
Date: 2023-04-25 20:01:34 UTC
SHA: 56d0482f982fd7b991442fd6b8fc62d4168647e3
21 changes: 12 additions & 9 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.3
Version: 1.2.4
Authors@R: c(
person("Michela", "Leonardi", role = "aut"),
person(c("Emily","Y."), "Hallet", role = "ctb"),
Expand All @@ -13,7 +13,7 @@ Authors@R: c(
Maintainer: Andrea Manica <[email protected]>
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>.
in Leonardi et al. (2023) <doi:10.1111/ecog.06481>.
License: CC BY 4.0
Language: en-GB
URL: https://github.com/EvolEcolGroup/pastclim,
Expand All @@ -22,19 +22,22 @@ BugReports: https://github.com/EvolEcolGroup/pastclim/issues
Encoding: UTF-8
LazyData: true
LazyDataCompression: xz
RoxygenNote: 7.2.2
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
Depends:
R (>= 4.0.0),
terra (>= 1.6.41)
methods,
terra (>= 1.7.18)
Imports:
curl,
ncdf4,
utils
Suggests:
rmarkdown,
knitr,
sf,
ggplot2,
testthat (>= 3.0.0)
rmarkdown,
knitr,
sf,
ggplot2,
testthat (>= 3.0.0),
spelling
VignetteBuilder: knitr
Config/testthat/edition: 3
6 changes: 5 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Generated by roxygen2: do not edit by hand

export("time_bp<-")
export(clean_data_path)
export(climate_for_locations)
export(climate_for_time_slice)
export(df_from_region_series)
export(df_from_region_slice)
export(distance_from_sea)
export(download_dataset)
export(get_available_datasets)
export(get_biome_classes)
Expand All @@ -17,7 +19,6 @@ export(get_time_steps)
export(get_vars_for_dataset)
export(is_region_series)
export(location_series)
export(location_series_old)
export(location_slice)
export(region_series)
export(region_slice)
Expand All @@ -31,4 +32,7 @@ export(time_series_for_locations)
export(update_dataset_list)
export(validate_nc)
export(var_labels)
exportMethods("time_bp<-")
exportMethods(time_bp)
import(methods)
import(terra)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# pastclim 1.2.4
* Updates on how time is handled to stay in sync with changes in `terra`.

# pastclim 1.2.3
* Added lai to Krapp2021 (the variable is now also present in the original OSF
repository for that dataset).
Expand Down
2 changes: 1 addition & 1 deletion R/check_var_downloaded.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Internal functions to check whether we have downloaded a given variable
#' Internal function to check whether we have downloaded a given variable
#' for a dataset
#'
#' @param variable a vector of names of the variables of interest
Expand Down
2 changes: 1 addition & 1 deletion R/clean_data_path.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Clean the data path
#'
#' This function deletes old reconstructions that have been superseded in the
#' data_path. It assumes that the only files in data_path are part of pastclim
#' data_path. It assumes that the only files in data_path are part of `pastclim`
#' (i.e. there are no custom datasets stored in that directory).
#'
#' @param ask boolean on whether the user should be asked before deleting
Expand Down
8 changes: 4 additions & 4 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@

#' Region outlines.
#'
#' An \code{sf} object containing outlines for major regions. Outlines that
#' An [`sf::sf`] object containing outlines for major regions. Outlines that
#' span the antimeridian have been split into multiple polygons.
#'
#' @format \code{sf} of outlines.
#' @format [`sf::sf`] of outlines.
#' \describe{
#' \item{name}{names of regions}
#' }
"region_outline"

#' Region outlines unioned.
#'
#' An \code{sf} object containing outlines for major regions. Each outline is
#' An [`sf::sf`] object containing outlines for major regions. Each outline is
#' represented as a single polygon. If you want multiple polygons, use
#' \link{region_outline}.
#'
#' @format \code{sf} of outlines.
#' @format [`sf::sf`] of outlines.
#' \describe{
#' \item{name}{names of regions}
#' }
Expand Down
6 changes: 3 additions & 3 deletions R/df_from_region_series.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#' Extract data frame from a region series
#'
#'
#' Extract the climatic information from a region series and organise them as
#' a data frame.
#'
#' To extract a data frame from a region slice, see \code{df_from_region_slice}.
#' To extract a data frame from a region slice, see [df_from_region_slice()].
#'
#' @param x climate time series generated with \code{region_series}
#' @param x climate time series generated with [region_series()]
#' @param xy a boolean whether x and y coordinates should be added
#' to the dataframe (default to TRUE)
#' @returns a data.frame where each cell each raster layer (i.e. timestep) is a
Expand Down
8 changes: 4 additions & 4 deletions R/df_from_region_slice.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#' Extract data frame from a region slice
#'
#' Extract the climatic information from a region slice and organise it as
#' a data frame. This is just a wrapper around \code{terra::as.data.frame}.
#' a data frame. This is just a wrapper around [terra::as.data.frame()].
#'
#' To extract a data frame from a region series, see \code{df_from_region_series}.
#' To extract a data frame from a region series, see [df_from_region_series()].
#'
#' @param x climate time slice (i.e. a \code{terra::SpatRaster})
#' generated with \code{region_slice}
#' @param x climate time slice (i.e. a [`terra::SpatRaster`])
#' generated with [region_slice()]
#' @param xy a boolean whether x and y coordinates should be added
#' to the dataframe (default to TRUE)
#' @returns a data.frame where each cell the raster is a
Expand Down
28 changes: 28 additions & 0 deletions R/distance_from_sea.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#' Compute a raster of distances from the sea for each land pixel.
#'
#' Get the land mask for a dataset at a given time point, and compute distance
#' from the sea for each land pixel.
#'
#' @param time_bp time slice in years before present (negative)
#' @param dataset string defining the dataset to use (a list of possible
#' values can be obtained with [get_available_datasets()]). This function
#' will not work on custom datasets.
#' @returns a [`terra::SpatRaster`] of distances
#'
#' @import terra
#' @export

distance_from_sea <- function(time_bp, dataset) {
this_land_mask <- get_land_mask(time_bp=time_bp,
dataset=dataset)
coastlines_polyline <- terra::as.polygons(this_land_mask) # first get polygon
coastlines_polyline <- terra::as.lines(coastlines_polyline) # then extract line

distances_rast <- terra::distance(this_land_mask$land_mask,
coastlines_polyline,
unit="km")
distances_rast <- terra::mask(distances_rast, this_land_mask)
names(distances_rast) <- "distance_from_sea"

return(distances_rast)
}
4 changes: 2 additions & 2 deletions R/download_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#'
#' This function downloads palaeoclimate reconstructions. Files will be stored
#' in the data path of `pastclim`, which can be inspected with
#' \code{get_data_path} and changed with \code{set_data_path}
#' [get_data_path()] and changed with [set_data_path()]
#'
#' @param dataset string defining dataset to be downloaded (a list of possible
#' values can be obtained with \code{get_available_datasets}). This function
#' values can be obtained with [get_available_datasets()]). This function
#' will not work on custom datasets.
#' @param bio_variables one or more variable names to be downloaded. If left
#' to NULL, all variables available for this dataset will be downloaded
Expand Down
3 changes: 2 additions & 1 deletion R/get_biome_classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' for a given dataset.
#'
#' @param dataset string defining dataset to be downloaded (a list of possible
#' values can be obtained with \code{get_available_datasets}). This function
#' values can be obtained with [get_available_datasets()]). This function
#' will not work on custom datasets.
#' @returns a data.frame with columns id and category.
#'
Expand Down Expand Up @@ -39,5 +39,6 @@ get_biome_classes <- function(dataset) {
category = biomes_string
)
}
ncdf4::nc_close(nc_in)
return(biome_categories)
}
2 changes: 1 addition & 1 deletion R/get_data_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' This function returns the path where climate reconstructions are stored.
#'
#' 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
#' a configuration file was saved when using [set_data_path()], the path
#' is retrieved from a file named "pastclim_data.txt", which
#' is found in the directory returned by
#' `tools::R_user_dir("pastclim","config")` (i.e.
Expand Down
2 changes: 1 addition & 1 deletion R/get_dataset_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' This function provides full information about a given dataset. A full
#' list of datasets available in pastclim can be obtained with
#' \code{get_available_datasets}
#' [get_available_datasets()]
#'
#' @param dataset A dataset in pastclim
#' @returns text describing the dataset
Expand Down
4 changes: 2 additions & 2 deletions R/get_file_for_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#'
#' @param variable one or more variable names to be downloaded
#' @param dataset string defining dataset to be downloaded (a list of possible
#' values can be obtained with \code{get_available_datasets}). This function
#' values can be obtained with [get_available_datasets()]). This function
#' will not work on custom datasets.
#' @returns the filename for taht variable and dataset
#' @returns the filename for that variable and dataset

get_file_for_dataset <- function(variable, dataset) {
check_available_variable(variable, dataset)
Expand Down
4 changes: 2 additions & 2 deletions R/get_ice_mask.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#'
#' @param time_bp time slice in years before present (negative)
#' @param dataset string defining dataset to be downloaded (a list of possible
#' values can be obtained with \code{get_available_datasets}). This function
#' values can be obtained with [get_available_datasets()]). This function
#' will not work on custom datasets.
#' @returns a binary \code{terra::SpatRaster} with the ice mask as 1s
#' @returns a binary [`terra::SpatRaster`] with the ice mask as 1s
#'
#' @import terra
#' @export
Expand Down
4 changes: 2 additions & 2 deletions R/get_land_mask.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#'
#' @param time_bp time slice in years before present (negative)
#' @param dataset string defining dataset to be downloaded (a list of possible
#' values can be obtained with \code{get_available_datasets}). This function
#' values can be obtained with [get_available_datasets()]). This function
#' will not work on custom datasets.
#' @returns a binary \code{terra::SpatRaster} with the land mask as 1s
#' @returns a binary [`terra::SpatRaster`] with the land mask as 1s
#'
#' @import terra
#' @export
Expand Down
4 changes: 2 additions & 2 deletions R/get_mis_time_steps.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#' Get the time steps available in a given dataset for a MIS.
#'
#' @param mis string giving the mis; it must use the same spelling as used in
#' /code{mis_boundaries}
#' [mis_boundaries]
#' @param dataset string defining dataset to be downloaded (a list of possible
#' values can be obtained with \code{get_available_datasets}). If set to
#' values can be obtained with [get_available_datasets()]). If set to
#' "custom", then a single nc file is used from "path_to_nc"
#' @param path_to_nc the path to the custom nc file containing the palaeoclimate
#' reconstructions. All the variables of interest need to be included in
Expand Down
7 changes: 1 addition & 6 deletions R/get_time_steps.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Get the time steps (in time_bp) available in a given dataset.
#'
#' @param dataset string defining dataset to be downloaded (a list of possible
#' values can be obtained with \code{get_available_datasets}). If set to
#' values can be obtained with [get_available_datasets()]). If set to
#' "custom", then a single nc file is used from "path_to_nc"
#' @param path_to_nc the path to the custom nc file containing the palaeoclimate
#' reconstructions. All the variables of interest need to be included in
Expand All @@ -24,9 +24,4 @@ get_time_steps <- function(dataset, path_to_nc = NULL) {

climate_nc <- terra::rast(path_to_nc, subds=1)
return(time_bp(climate_nc))

# climate_nc <- ncdf4::nc_open(path_to_nc)
# time_steps <- (climate_nc$dim$time$vals)
# ncdf4::nc_close(climate_nc)
# return(time_steps)
}
2 changes: 1 addition & 1 deletion R/get_vars_for_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' different reconstructions.
#'
#' @param dataset string defining dataset to be downloaded (a list of possible
#' values can be obtained with \code{get_available_datasets}).
#' values can be obtained with [get_available_datasets()]).
#' @param path_to_nc the path to the custom nc file containing the palaeoclimate
#' reconstructions.
#' @param details boolean determining whether the output should include information
Expand Down
8 changes: 4 additions & 4 deletions R/is_region_series.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#' Check the object is a valid region series
#'
#' A region series is a \code{terra::SpatRasterDataset} for which each
#' A region series is a [`terra::SpatRasterDataset`] for which each
#' sub-dataset is a variable, and all variables have the same number of
#' time steps.
#'
#' The standard test only checks that each SpatRaster has the same number of
#' layers. The more thorough test (obtained with strict=TRUE) actually checks
#' that all time steps are identical by comparing the result of
#' \code{terra::time} applied to each variable
#' [terra::time()] applied to each variable
#'
#' @param x a \code{terra::SpatRasterDataset} representing a time series of
#' regional reconstructions obtained from \code{region_series}.
#' @param x a [`terra::SpatRasterDataset`] representing a time series of
#' regional reconstructions obtained from [region_series()].
#' @param strict a boolean defining whether to preform a thorough test (see
#' description above for details).
#' @returns TRUE if the object is a region series
Expand Down
2 changes: 1 addition & 1 deletion R/load_dataset_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' This function returns a dataframe with the details for each variable
#' available in every dataset. It defaults to the copy stored within the
#' package, but it checks in case there is an udpated version stored as
#' package, but it checks in case there is an updated version stored as
#' 'data_list.csv' in
#' `tools::R_user_dir("pastclim","config")`. If the latter is present, the last
#' column, named 'dataset_list_v', provides the version of this table, and the
Expand Down
Loading

0 comments on commit d5d7427

Please sign in to comment.