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

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