Rasters are sometimes file-based, so the normal save and copy and assign mechanisms in R don't work for saving, copying and assigning. This function creates an explicit file copy of the file that is backing the raster, and changes the pointer (i.e., filename(object)) so that it is pointing to the new file.

.prepareFileBackedRaster(obj, repoDir = NULL, overwrite = FALSE, ...)

Arguments

obj

The raster object to save to the repository.

repoDir

Character denoting an existing directory in which an artifact will be saved.

overwrite

Logical. Should the raster be saved to disk, overwriting existing file.

...

passed to archivist::saveToRepo

Value

A raster object and its newly located file backing. Note that if this is a legitimate archivist repository, the new location will be a subdirectory called rasters/ of repoDir/. If this is not a repository, the new location will be within repoDir.

Examples

library(raster) archivist::createLocalRepo(tempdir())
#> Directory /tmp/RtmpqKjqWd does exist and contain the backpack.db file. Use force=TRUE to reinitialize.
r <- raster(extent(0,10,0,10), vals = 1:100) # write to disk manually -- will be in tempdir() r <- writeRaster(r, file = tempfile()) # copy it to the cache repository r <- .prepareFileBackedRaster(r, tempdir()) r # now in "rasters" subfolder of tempdir()
#> class : RasterLayer #> dimensions : 10, 10, 100 (nrow, ncol, ncell) #> resolution : 1, 1 (x, y) #> extent : 0, 10, 0, 10 (xmin, xmax, ymin, ymax) #> coord. ref. : NA #> data source : /tmp/RtmpqKjqWd/rasters/filed6434fd8a3ed.grd #> names : layer #> values : 1, 100 (min, max) #>