# \donttest{
filePath <- system.file("external/", package="climetrics") # path to the dataset folder
# read the climate variables using the terra package (you can use the raster package as well):
pr <- rast(paste0(filePath,'/precip.tif'))
tmean <- rast(paste0(filePath,'/tmean.tif'))
pr # has 360 layers corresponds to months of the years 1991-2020
n <- readRDS(paste0(filePath,'/dates.rds')) # read corresoinding dates
head(n) # Dates corresponds to the layers in climate variables (pr, tmin, tmax, tmean)
####################
# use rts function in the rts package to make a raster time series:
pr.t <- rts(pr,n)
tmean.t <- rts(tmean,n)
###########################
# test of the metric:
n1 <- novelClimate(pr.t,tmean.t,t1='1991/2000',t2='2010/2020')
plot(n1, main='Novel Climate')
######
# if the input object is SpatRaster (or RasterStack or RasterBrick) object:
# t1 and t2 would be the numbers specifying which layers correspond to time1 and time2:
n2 <- novelClimate(pr,tmean,t1=1:120,t2=229:360)
plot(n2)
# }
Run the code above in your browser using DataLab