with_tempfile {withr} | R Documentation |
Temporarily create a tempfile, which is automatically removed afterwards.
with_tempfile( new, code, envir = parent.frame(), pattern = "file", tmpdir = tempdir(), fileext = "" ) local_tempfile( new, envir = parent.frame(), pattern = "file", tmpdir = tempdir(), fileext = "" )
new |
|
code |
|
envir |
|
pattern |
a non-empty character vector giving the initial part of the name. |
tmpdir |
a non-empty character vector giving the directory name |
fileext |
a non-empty character vector giving the file extension |
[any]
The results of the evaluation of the code
argument.
withr
for examples
# check how big iris would be if written as csv vs RDS with_tempfile("tf", {write.csv(iris, tf); file.size(tf)}) with_tempfile("tf", {saveRDS(iris, tf); file.size(tf)})