Since I updated RStudio last day I cannot get Rstudio to drop it's hold on my excelfiles.
I've tried the following to no avail:
unlink(fileName, recursive = TRUE)
file.info(fileName)
file.remove(fileName)
file.info gives the following:
size 2383465
isdir FALSE
mode 666
mtime 2020-08-06 11:02:03
ctime 2020-06-16 13:00:22
atime 2020-08-06 10:40:30
exe no
RStudio is installed by an administrator but I personally don't hold admin-privileges in my organization. file.remove isn't permitted even with unlink (but it's not a dir so...). And I don't really want to remove it, just get Rstudio to drop the hold. The file will be modified in Excel (and saved, which is not permitted since RStudio holds it).
UPDATE:
I guess this is a bug, so all my googling have found no solution so far. One workaround I guess would be able to fix this is if I could programmatically re-initialize the JVM-instance. (for instance, .rs.restartR()
do drop the R:s hold on the file)
UPDATE 2 :
The exact same error happens with the openxlsx-package, which is not dependant on Java so the problem is probably with R.
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=Swedish_Finland.1252 LC_CTYPE=Swedish_Finland.1252 LC_MONETARY=Swedish_Finland.1252
[4] LC_NUMERIC=C LC_TIME=Swedish_Finland.1252
UPDATE 3:
Still no breakthrough here, I've solved the lock with a bit of hacky-code but it solves the immediate problem atleast:
.rs.restartR()
source("~/.Rprofile")
UPDATE 4:
If I do this:
library(XLConnect)
wb <- loadWorkbook("Cars.xlsx", create = TRUE)
createSheet(wb, "Data")
writeWorksheet(wb, cars, "Data")
saveWorkbook(wb)
The first time a open the file, I can save without closing the R-session. If I do that, open the Excel-file and save, and then re-run the above code my R-session hold the permission lock. So it has something within the scope the file is saved.
UPDATE 5:
This is now an open Issue, probably Windows-only bug:
.Rhistory
and.Rprofile
files. – Pearcy.Rhistory
and.Rprofile
to clear this variable, and with a bit of care trying to avoid the same situation in the future. :-) – Pearcy