unlink
Remove Files and Directories

Description

Deletes the file or directory represented by x.

Usage

unlink(x, recursive = FALSE, force = FALSE) 

Arguments

x a character string that specifies a file or directory name, or a vector that specifies a set of files or directories. The names are interpreted literally; that is, you cannot use UNIX regular expression expansions to specify file or directory names.
recursive a logical value. If TRUE, the directories are deleted recursively. If FALSE (the default), directories are never deleted.
force This argument is not yet implemented. a logical value. If TRUE, the restrictive permissions of the file or directory is changed as possible to allow it to be removed like rm -f command. The default is FALSE.

Details

When you use unlink to remove a file created within a function, it is good programming style to use on.exit(unlink(file)) so the file is removed even if the function is exited abnormally. unlink removes files and directories, but for directories, only when recursive=TRUE.
Value
returns an integer value. If the return value is 0, then either all of the files and directories were successfully removed or they did not exist. If the return value is 1, an error occurred.
Side Effects
The files and directories that you specified in x are removed.
See Also
unix, tempfile, on.exit,
Examples
# set up temp file and remove on exit
foo <- function() {
	file <- tempfile("junk")
	on.exit(unlink(file))
	# do something with file
	TRUE
}

file1 <- tempfile("test") res <- unlink("test") res res <- unlink("test1") res

unlink("res_test", force = TRUE) # "res_test" is a file with restrictive permissions.

Package base version 6.1.1-7
Package Index