How to fix this error for raster package in R?

Viewed 21

I just started learning GIS via R, and I am using the raster package. It gives me the following error when I use the geodata package.

Error: 'geodata' is not an exported object from 'namespace:raster'

I used the following code:

States <- raster::geodata(name = "GADM",
                          country = "United States",
                          level = 1,
                          path = "path/to/save/file",
                          download = TRUE)

Found something similar on Stack Echange already answered here ('data' is not an exported object from 'namespace:my_package') but I believe it was a different context.

1 Answers

raster::geodata simply does not exist (and that is what the message tells you).

You are probably looking for the outdated:

States <- raster::getData("GADM", country = "United States",
                      level = 1, path = ".")

And mixing that up with the replacement

s <- geodata::gadm("United States", level = 1, path = ".")

(but note that geodata returns "terra" objects. "terra" is the replacement of "raster")

Related