Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the new CMIP6 data with geodata #27

Closed
maurobio opened this issue Sep 13, 2022 · 3 comments
Closed

How to use the new CMIP6 data with geodata #27

maurobio opened this issue Sep 13, 2022 · 3 comments

Comments

@maurobio
Copy link

maurobio commented Sep 13, 2022

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?

@Rapsodia86
Copy link

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)

@rhijmans
Copy link
Member

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")

@maurobio
Copy link
Author

maurobio commented Sep 22, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants