tempfile {base}R Documentation

Create Names for Temporary Files

Description

tempfile returns a vector of character strings which can be used as names for temporary files.

Usage

tempfile(pattern = "file", tmpdir = tempdir())
tempdir()

Arguments

pattern a non-empty character vector giving the initial part of the name.
tmpdir a non-empty character vector giving the directory name

Details

If pattern has length greater than one then the result is of the same length giving a temporary file name for each component of pattern.

The names are very likely to be unique among calls to tempfile in an R session and across simultaneous R sessions. The filenames are guaranteed not to be currently in use.

tempdir() gives a subdirectory of the first found of the environment variables TMP, TEMP and R_USER (see Rconsole) which points to a writeable directory. If the path to the directory contains a space in any of the components, the path returned will use the shortnames version of the path.

Value

For tempfile a character vector giving the names of possible (temporary) files. Note that no files are generated by tempfile.
For tempdir, the path of the per-session temporary directory.
Both will use backslash as the path separator.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

unlink for deleting files.

Examples

tempfile(c("ab", "a b c"))   # give file name with spaces in!

tempdir() # working on all platforms with quite platform dependent result

[Package base version 2.1.0 Index]