I read this post on how to delete tmp files. The solution in that post is:
do.call(file.remove, list(list.files("C:/Temp", full.names = TRUE)))
The directory "C:/Temp" is presumably fine with windows machines. Since I'm on linux I wasn't sure what my tmp file dir was so I did this:
tmp <- tempfile()
Which returns: "/tmp/RtmpNS80no/file147c37e54e8e"
So, I tried this:
do.call(file.remove, list(list.files("tmp", full.names = TRUE)))
This returns "logical(0)" so presumably did not work?
How do I delete all my tmp files?
You can get the temp directory for the current R session. It does not change when called several times
The temp directory contains the temp files and directory for the current R session
The session temp directory is in the temp directory of the system. You can use this path if you want to delete all in the temp directory of the system (not recommended though because it is for all the system, not just R temp files)
This path is also contains in an environnement variable for the OS. (Obviously, I am on windows)
tempfile()
gives the path of a possible temporary file, in thetempdir()
directory by default, with no file extension. The file is not created andtempfile
gives different values when calls several timesWe can write something to tmp_file.
We can read from this file
Now if you want to delete this file
If you want to delete all files in the R session temp folder, you can use
file.remove
on a list of files. For this example purpose, I deleted all temp file beginning with "file" ("^file"
is a regex for that pattern). There are more than I created - R session seems to create some temp file along the way.I get a warning because there is a file I can't delete (probably in use by R right now)
If you want to remove a folder you can use
unlink
too