Clone an existing file to a new location. This is typically performed inside saveObject methods for objects that contain a reference to a file.

cloneFile(src, dest, action = c("link", "copy", "symlink", "relsymlink"))

Arguments

src

String containing the path to the source file.

dest

String containing the destination file path, typically within the path supplied to saveObject.

action

String specifying the action to use when cloning src to dest.

  • "copy": copy src to dest.

  • "link": create a hard link from src to dest. If this fails, we silently fall back to a copy.

  • "symlink": create a symbolic link from src to dest. The symbolic link contains the absolute path to src, which is useful when dest might be moved but src will not.

  • "relsymlink": create a symbolic link from src to dest. Each symbolic link contains the minimal relative path to src, which is useful when both src and dest are moved together, e.g., as they are part of the same parent object like a SummarizedExperiment.

Value

A new file/link is created at dest. NULL is invisibly returned.

See also

cloneDirectory, to clone entire directories.

Author

Aaron Lun

Examples

tmp <- tempfile()
write(file=tmp, LETTERS)

dest <- tempfile()
cloneFile(tmp, dest)
readLines(dest)
#>  [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S"
#> [20] "T" "U" "V" "W" "X" "Y" "Z"