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

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)


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)


Just to update everyone, I (think that I) found out the source of the problem: antivirus.

The "real time file system protection" was blocking R from copying the files between folders once they were downloaded. Upon adding the R directory to the exception list (coupled with adding user permission and installing R on D:\R), and the problem went away. With all of this work, I might as well switch to Linux (I should, really...)

(I updated my post with the above information: http://www.r-statistics.com/2011/04/how-to-upgrade-r-on-windows-7/)

I hope it will help someone in the future, Tal


If you cannot turn off your antivirus, due to corporate policy for example, here is a workaround that I found. Debugging the unzip package function and then stepping through it gives the antivirus enough time to do its job without interfering. Use this command:

debug(utils:::unpackPkgZip)
install.packages("packageName")

and then step through the code (by pressing enter many times) when R starts debugging during the installation.

I found this solution here.