File and Directory Manipulation

DESCRIPTION:

These functions provide file and directory manipulation from within S-PLUS. They can check for existence, create, copy, rename, remove, append to files and create directories.

USAGE:

file.create(...)
file.exists(...)
file.remove(...)
file.rename(from, to)
file.append(file1, file2)
file.copy(from, to, overwrite=FALSE)
dir.create(path, showWarnings=TRUE, recursive=FALSE)

REQUIRED ARGUMENTS:

..., from, to, file1, file2
character vectors containing file names. The ... arguments are concatenated to form one vector of character values.
path
a character vector giving a single path name.

OPTIONAL ARGUMENTS:

overwrite
a logical value; if TRUE, the destination file(s) will be overwritten if they exist.
showWarnings
a logical value; if TRUE warnings on directory creation are show.
recursive
a logical value; if TRUE all elements in path will be created if they do not already exist.

VALUE:

a logical vector the length of the combined arguments, TRUE indicates a successful operation for that element.

SIDE EFFECTS:

Files or directories are created, removed, copied or appended to.

DETAILS:

file.create creates files with the specified names. If the file already exists, it is truncated to length zero.

file.exists returns a logical vector the length of the combined arguments that is TRUE if that file exists.

file.remove removes the specified files.

file.rename renames the single file given by from to the name given in to.

file.append appends the contents of the files given in file2 to the files given in file1.

file.copy copies the files given by from to the names given in to. The to argument can specify a single existing directory.

dir.create creates the single directory unless recursive is TRUE, then all necessary directories specified in path are created.

SEE ALSO:

, , , .

EXAMPLES:

tfile1 <- tempfile("a")
tfile2 <- tempfile("b")
tfile3 <- tempfile("c")
cat("This is file 1\n", file=tfile1)
cat("This is file 2\n", file=tfile2)
file.append(tfile1, tfile2)
file.copy(tfile1, tfile3)
file.remove(tfile1)
file.exists(tfile1)
tdir <- tempfile("d")
dir.create(tdir)
file.copy(c(tfile2, tfile3), tdir)
list.files(tdir)
# Clean up:
unlink(c(tfile1, tfile2, tfile3, tdir))