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

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 all files within src to their corresponding locations in dest.

  • "link": create a hard link from each file in src to its corresponding location in dest. If this fails, we silently fall back to a copy.

  • "symlink": create a symbolic link from each file in src to its corresponding location in dest. Each symbolic link contains the absolute path in the corresponding file in its 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 each file in src to its corresponding location in dest. Each symbolic link contains the minimal relative path to the 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.

See also

cloneFile, to clone individual files.

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"