Skip to contents

Finds and orders the monthly files of one variable in a folder, e.g. the files written by download_chelsa_monthly() or downloaded by hand. A file belongs to variable var and month MM when its name contains _<var>_<MM>_ (so tas does not match tasmax); the month may be written 01 or 1, as in CHELSA-TraCE21k.

Usage

monthly_files(dir, var, must_contain = NULL)

Arguments

dir

Folder with the files.

var

Variable, e.g. "tasmax".

must_contain

Optional text(s) the file name must also contain (case-insensitive), e.g. the GCM and scenario: c("mpi-esm1-2-hr", "ssp370"), or "1981-2010".

Value

12 file paths, January to December.

References

Karger, D.N., Conrad, O., Bohner, J., et al. (2017) Climatologies at high resolution for the earth's land surface areas. Scientific Data 4, 170122. doi:10.1038/sdata.2017.122

Examples

d <- tempfile()
dir.create(d)
for (m in 1:12) file.create(file.path(d, sprintf("CHELSA_tas_%02d_1981-2010_V.2.1.tif", m)))
basename(monthly_files(d, "tas"))[1:2]
#> [1] "CHELSA_tas_01_1981-2010_V.2.1.tif" "CHELSA_tas_02_1981-2010_V.2.1.tif"