symlink: Create a symbolic link to a file, adjusting paths...

View source: R/symlink.R

symlinkR Documentation

Description

This function creates a symbolic (soft) link to a file, in a solution that works for all major operating systems, so a file can have two names without actually duplicating data. Although the two paths can be specified directly, this function automatically handles a conversion for a common but troublesome case when the link is not in the current directory, in which case the file must be relative to the parent directory of the link, although it is more natural to specify the file relative to the current directory.

Usage

symlink(file, link, adjust_path = TRUE, verbose = TRUE)

Arguments

file

The file that will be linked. This function does not require this file to exist, but the link will be broken in that case.

link

The path to the link to the file. If this points to an existing file, or an existing link, it will be overwritten.

adjust_path

If TRUE (default), file is automatically adjusted in the special case in which it is a relative path (assumed to be relative to current directory) but link is not in the current directory, in which case file is adjusted to be relative to the parent directory of link. If file is an absolute path, it is never edited, and likewise no editing is needed if link is in the current directory. Set to FALSE to avoid editing in all cases.

verbose

If TRUE (default), function reports the link and the final file it points to.

Examples

# in this example, for the existing file, use this file provided by the package.
# Note that it is an absolute path, so it will not be edited.
file <- system.file("extdata", 'sample.bed', package = "genio", mustWork = TRUE)
# this is the path to the link
link <- tempfile('delete-me-example', fileext = '.bed')

# create the symbolic link!
symlink( file, link )

# delete example link when done
file.remove( link )


OchoaLab/genio documentation built on Feb. 22, 2025, 4:13 a.m.