Update file path metadata for file-backed objects (e.g., SpatRasters). Useful when moving saved objects between projects or machines.

remapFilenames(obj, tags, cachePath = getOption("reproducible.cachePath"), ...)

Arguments

obj

(optional) object whose file path metadata will be remapped

tags

cache tags data.table object

cachePath

character string specifying the path to the cache directory or NULL

...

Additional path arguments, passed to absoluteBase() and modifyListPaths()

Examples

# A file-backed object cached on one machine records where its files lived.
# remapFilenames() translates those to where they belong on THIS machine,
# using the anchors (e.g. inputPath) supplied in `paths`.
inputDir <- file.path(tempdir(), "remapExample")
dir.create(inputDir, showWarnings = FALSE)

tags <- c(
  "origFilename:dem.tif",
  "origRelName:dem.tif",
  "relToWhere:inputPath", # the anchor the file was stored relative to
  "filesToLoad:/some/other/machine/inputs/dem.tif"
)

newFiles <- remapFilenames(
  tags = tags, cachePath = NULL,
  paths = list(inputPath = inputDir)
)
newFiles$newName # now under THIS machine's inputPath
#> [1] "/tmp/RtmpGYQuF2/remapExample/dem.tif"

unlink(inputDir, recursive = TRUE)