Learn R Programming

reproducible (version 3.2.1)

remapFilenames: Remap file names

Description

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

Usage

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

Run this code
if (FALSE) { # identical(Sys.getenv("NOT_CRAN"), "true")
# 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

unlink(inputDir, recursive = TRUE)
}

Run the code above in your browser using DataLab