Windows 7, update.packages problem: "unable to move temporary installation"?

Tal Galili picture Tal Galili · Apr 18, 2011 · Viewed 83.4k times · Source

I am using R 2.13.0 with windows 7, after giving my user full privileges to the R folder (as described here). This allows me to install new packages just fine.

However, when using update.packages(), to update existing packages, I keep getting the following error (for example, when updating the MASS package):

package 'MASS' successfully unpacked and MD5 sums checked

Warning: unable to move temporary installation 'C:\Program Files\R\R-2.13.0\library\file6cae3bcf\MASS' to 'C:\Program Files\R\R-2.13.0\library\MASS'

Any suggestions on how to fix this?

p.s: Running R as an administrator or shifting the library location out of Program Files is not a solution (it's a hack - but I am looking for a solution)

Answer

Mads Sønderkær picture Mads Sønderkær · Sep 4, 2017

I found that the problem indeed is the antivirus "real time file system protection". I do the following to fix the problem:

trace(utils:::unpackPkgZip, edit=TRUE)

I edit line 140 (line 142 in R 3.4.4):

Sys.sleep(0.5)

to:

Sys.sleep(2)

I seems like the antivirus stalls the creation of the package tmp dir. After changing it to 2 seconds the error is gone.

EDIT: to do this programmatically execute

trace(utils:::unpackPkgZip, quote(Sys.sleep(2)), at = which(grepl("Sys.sleep", body(utils:::unpackPkgZip), fixed = TRUE)))

(credits @DavidArenburg)