Clone an existing directory to a new location. This is typically performed inside saveObject after detecting duplicated objects, see ?createDedupSession for details.

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

Arguments

src

String containing the path to the source directory, typically generated by a prior saveObject call.

dest

String containing the path to the destination directory, typically the path in a subsequent saveObject call..

action

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

  • "copy": copy the files from src to dest.

  • "link": create a hard link from the files in src to their new locations in dest. If this fails, we silently fall back to a copy. This mode is the default approach.

  • "symlink": create a symbolic link from the files in src to their new locations in dest. Each symbolic link refers to an absolute path in the original directory, which is useful when the contents of dest might be moved (but the original directory will not).

  • "relsymlink": create a symbolic link from the files in src to their new locations in dest. Each symbolic link refers to an relative path to its corresponding file in the original directory, 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 directory is created at dest with the contents of src, either copied or linked. NULL is invisibly returned.

Author

Aaron Lun

Examples

tmp <- tempfile()
dir.create(tmp)

src <- file.path(tmp, "A")
dir.create(src)
write(file=file.path(src, "foobar"), LETTERS)

dest <- file.path(tmp, "B")
cloneDirectory(src, dest)
list.files(dest, recursive=TRUE)
#> [1] "foobar"