How to use the new CMIP6 data with geodata
maurobio opened this issue · 3 comments
Hi
I am trying to adapt the example from here (https://rstudio-pubs-static.s3.amazonaws.com/224303_df34f170cd9144cda6477ae8232887f7.html), which uses the CMIP5 data (now obsolete), to the latest WorldClim models (http://www.worldclim.org/) using the new CMIP6 data,
For retrieving the data, I am using the geodata package.
Here is the script as far as I could run it:
[edited to just show the relevant part]
library(geodata)
# Get climate data
currentEnv <- worldclim_global(var="bio", res=2.5, path=getwd())
currentEnv <- dropLayer(currentEnv, c("bio2", "bio3", "bio4", "bio10", "bio11", "bio13", "bio14", "bio15"))
#Error in (function (classes, fdef, mtable) :
# unable to find an inherited method for function ‘dropLayer’ for signature ‘"SpatRaster"’
Could a working example of using the latest CMIP6 data with geodata be provided?
The error says that there is not function 'dropLayer' in the terra package.
Here are examples how to drop a layer:
rspatial/terra#664 (comment)
This is not really the place for Q&A (see e.g. stackoverflow for that),
Anyway, currentEnv
is a SpatRaster
(a class defined by "terra") but you are treating it like a RasterStack
or RasterBrick
(from the "raster" package). This means that you may have to either change more things in your script, or use
library(raster)
currentEnv <- as(currentEnv, "Raster")