Romain
Romain

Reputation: 859

Remove a file that has been opened within R studio with read.xlsx

I am doing a loop on different file and need to read a file extract the information and then delete it.

In R I use the package openxlsx

datatemp = openxlsx::read.xlsx(xlsxFile = "./source/aFile.xlsx")

However I can't remove the file from windows, it tells me it is open in R studio, I tried to point read.xlsx to another file, and to closeAllConnections but it did not work.

Is there a way to disconnect R from the file without having to close R studio ?

Thanks

Romain

Upvotes: 3

Views: 3110

Answers (1)

Stedy
Stedy

Reputation: 7469

I am on Windows 7 and I used unlink which let me delete the file

datatemp = openxlsx::read.xlsx(xlsxFile = "temp.xlsx")
unlink(datatemp)

Then I was able to manually delete the file without a problem

Upvotes: 3

Related Questions