cp: Copy Files

Description Usage Arguments Value Note See Also Examples

View source: R/cp.R

Description

Copy or move files, overwriting existing files if necessary, and returning the result invisibly.

Usage

1
cp(from, to, move = FALSE, ignore = FALSE, overwrite = TRUE, quiet = TRUE)

Arguments

from

source filenames, e.g. *.csv.

to

destination filenames, or directory.

move

whether to move instead of copy.

ignore

whether to suppress error if source file does not exist.

overwrite

whether to overwrite if destination file exists.

quiet

whether to suppress messages.

Value

TRUE for success, FALSE for failure, invisibly.

Note

To prevent accidental loss of files, two safeguards are enforced when move = TRUE:

  1. When moving files, the to argument must either have a filename extension or be an existing directory.

  2. When moving many files to one destination, the to argument must be an existing directory.

If these conditions do not hold, no files are changed and an error is returned.

See Also

file.copy and unlink are the underlying functions used to copy and (if move = TRUE) delete files.

file.rename is the base function to rename files.

TAF-package gives an overview of the package.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
write(pi, "A.txt")
cp("A.txt", "B.txt")
cp("A.txt", "B.txt", move=TRUE)

## Copy directory tree
cp(system.file(package="datasets"), ".")
mkdir("everything")
cp("datasets/*", "everything")

## End(Not run)

TAF documentation built on April 7, 2021, 5:06 p.m.