Karsten W.
Karsten W.

Reputation: 18500

How can I remove temporary folders under Windows with R?

After a session I would like to clean up my temporary folders, like for instance

d <- tempfile()
dir.create(d)
setwd(d)
# now work and sweave and latex etc

How can I remove d and its elements? file.remove fails.

Upvotes: 6

Views: 5031

Answers (2)

diliop
diliop

Reputation: 9451

Try ?unlink. Depends on what os you are using but this:

unlink(d, recursive=TRUE)

Should work. If you want to delete the contents and reuse the folder you could try this:

file.remove(dir(d, full.names=TRUE))

Upvotes: 4

user399470
user399470

Reputation:

Try unlink("d", recursive=TRUE). That should delete the folder and its contents.

Upvotes: 7

Related Questions