R-CMD-check master R-CMD-check dev codecov

This R library is designed to provide an easy way to extract and manipulate palaeoclimate reconstructions for ecological and anthropological analyses.

The functionalities of pastclim are described in Leonardi et al. (2023). Please cite it if you use pastclim in your research.

Install the library

pastclim is on CRAN, and the easiest way to install it is with:

{r install_cran, eval=FALSE} install.packages("pastclim")

If you want the latest development version, you can get it from GitHub. To install from GitHub, you will need to use devtools; if you haven’t done so already, install it from CRAN with install.packages("devtools"). Also, note that the dev version of pastclim tracks changes in the dev version of terra, so you will need to upgrade to both:

{r install_dev, eval=FALSE} install.packages('terra', repos='') devtools::install_github("EvolEcolGroup/pastclim", ref="dev")

Overview of functionality

On its dedicated website, you can find Articles giving you a step-by-step overview of the package, and a cheatsheet. There is also a version of the site updated for the dev version (on the top left, the version number is in red, and will be in the format x.x.x.9xxx, indicating it is a development version).

Pastclim currently includes data from Beyer et al 2020, a reconstruction of climate based on the HadCM3 model for the last 120k years, and Krapp et al 2021, which covers the last 800k years. The reconstructions are bias-corrected and downscaled to 0.5 degree. More details on these datasets can be found here. There are also instructions on how to build and use custom datasets.

You can also build the vignettes when installing pastclim (note that you will need to have the necessary tools to build vignettes already installed; requirements depend on your OS):

devtools::install_github("EvolEcolGroup/pastclim", build_vignette = TRUE)

If you built the vignettes, you can read them directly in R. For example, the overview can be obtained with:

vignette("pastclim_overview", package = "pastclim")

Current issues

If something does not work, check the issues on GitHub to see whether the problem has already been reported. If not, feel free to create an new issue. Please make sure you provide a reproducible example for the developers to investigate the problem.

Error in x$.self$finalize()

pastclim relies on terra to process rasters. There is a known bug in terra that leads to the occasional message:

"Error in x$.self$finalize() : attempt to apply non-function"

This is an error related to garbage collection, which does not affect the script being correctly executed, so it can be ignored. More discussion of this issue can be found on stackoverflow

terra without NETCDF driver for macOS

A number of versions of terra available as binaries for macOS X86-64 on CRAN (including the latest one) have been compiled without a NETCDF driver (the latest ARM library is OK). This prevents pastclim, which relies on terra, from correctly reading files. Other packages that rely on terra are similarly affected (e.g. stars; see this bug)

When loaded, pastclim checks if the driver is available; in case of a missing driver, you will get the error:

Error: The installed version of terra lacks support for reading netcdf files.
pastclim needs netcdf support: you will need to reinstall terra,
possibly from source, if there isn't a version with netcdf support
on CRAN. Alternatively, try the latest development version from R-universe:
install.packages('terra', repos='')

The easiest solution is probably to install the dev version of terra from R-universe with:

install.packages('terra', repos='')

However, note that the dev version of terra is incompatible with the version of pastclim on CRAN. Therefore, you need to also upgrade pastclim to dev:

devtools::install_github("EvolEcolGroup/pastclim", ref="dev")

Alternatively, if you want to install a specific version of terra from source, see instructions here.

no slot of name “ptr” with dev version of terra

the dev version of terra is incompatible with the version of pastclim on CRAN, leading to the following error.

Error in time_bp(climate_nc) : no slot of name "ptr" for this object of class "SpatRaster"

To solve this, you need to also upgrade pastclim to dev:

devtools::install_github("EvolEcolGroup/pastclim", ref="dev")