aldo_tapia aldo_tapia - 29 days ago 18
R Question

How to save raster data in R object format?

I don't know how to deal with

save.image()
and
saveRDS()
with raster data in R. I have understood that raster package open a connexion with the image file using
raster()
function, so it doesn't really open the file into R workspace.

I want to save my workspace (data.frame, list, raster, etc) with
save.image()
function (or similar) and open it in a different computer. If I try to plot or process a raster object saved in a different computer, always have the same issue:

Error in .local(.Object, ...) :
`C:\path\to\file.tif' does not exist in the file system,
and is not recognised as a supported dataset name.


Is there a way to save a raster object (opened as external file) in R format? I don't mean raster format as tiff nor grid and others.

Answer

You can save rasters, like other R objects, using the save command.

save(r,file="r.Rdata")

On a different computer, you can load that file using

load("r.Rdata")

which will bring back the raster r in your workspace.

I have tried this across Windows and Linux and it never gives problems