Removes Files and Directories

DESCRIPTION:

Deletes the file or directory represented by x.

USAGE:

unlink(x, recursive=F) 

REQUIRED ARGUMENTS:

x
character string giving the name of a file. This may actually be a vector naming more than one file. The names are interpreted just as given; that is, none of the various UNIX regular expression expansions may be used.

OPTIONAL ARGUMENTS:

recursive
a logical value; if TRUE directories are deleted recursively.

VALUE:

a logical vector the length of the input: TRUE means that the file was removed. The error attribute gives a short description of why the C unlink or rmdir functions failed.

SIDE EFFECTS:

The named files and directories are removed.

DETAILS:

When using unlink to remove a file created within a function, it is good programming style to use on.exit(unlink(file)) so that the file will be removed even if the function is exited abnormally.

unlink will remove files and directories, but only empty directories unless recursive=TRUE. You can also use rmdir to remove a directory and everything in it.

SEE ALSO:

, , , .

EXAMPLES:

# set up temp file and remove on exit 
foo <- function() { 
        file <- tempfile("junk") 
        on.exit(unlink(file)) 
        ... 
}