tests/tmpfile.R

library("R.utils")

## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
## Assert that auto delete works
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

## Temporary files before
tfiles <- dir(path=tempdir(), full.names=TRUE)

## Create temporary file on the fly without any references to it
bfr <- readLines(tmpfile("Hello world!\n"))
print(bfr)

## Find new temporary file
tfile <- setdiff(dir(path=tempdir(), full.names=TRUE), tfiles)
print(tfile)
stopifnot(file.exists(tfile))

## The on-the-fly temporary file is removed
## whenever the garbage collector runs
gc()
stopifnot(!file.exists(tfile))

Try the R.utils package in your browser

Any scripts or data that you put into this service are public.

R.utils documentation built on Nov. 18, 2023, 1:09 a.m.