76

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)

Community
  • 1
  • 1
Tal Galili
  • 24,605
  • 44
  • 129
  • 187
  • 1
    Related question: http://stackoverflow.com/questions/5059692/unable-to-update-r-packages-in-default-library-on-windows-7 – Andrie Apr 18 '11 at 08:59
  • It's a warning only. What is the result of `sessionInfo(package="MASS")` ? – Andrie Apr 18 '11 at 09:19
  • 2
    You're on Windows. So the only solid solution will be to install R outside of the Program Files. Are you sure the MASS package isn't loaded when you try to update? I.e. do you get the same warning when updating after you did `detach(package:MASS)`? – Joris Meys Apr 18 '11 at 09:32
  • @Andrie : true, I was a bit quick. Yet, it's a warning that makes clear that the MASS package is not updated. – Joris Meys Apr 18 '11 at 09:33
  • Hi Joris, I've tried running R as admin, and changing file permissions as much as I could, but none seem to work. It appears that the only solution is indeed to have R installed outside the program files folder (what a shame...) – Tal Galili Apr 18 '11 at 12:45
  • I installed R outside of Program Files and it still doesn't work – xiaodai Oct 18 '13 at 09:01
  • 4
    I am coming here six years later, trying to install packages for R 3.4.2 and getting this problem. Go figure. Interestingly enough, it's an intermittent problem - sometimes installing works, sometimes it doesn't. May depend on what signatures the antivirus scanner recently downloaded. [Sheldon's answer](https://stackoverflow.com/a/44256520/452096) worked better than going to corporate IT. – Stephan Kolassa Oct 19 '17 at 07:50

13 Answers13

106

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)

Gerhard Burger
  • 1,379
  • 1
  • 16
  • 25
Mads Sønderkær
  • 1,076
  • 1
  • 8
  • 2
  • 7
    I've done that repeatedly now (which does work _temporarily_), but for some reason the edit won't stick... after a while or on any session restart it goes back to `Sys.sleep(0.5)`. How do I get the edit to be permanent? – JSCard Oct 05 '17 at 14:02
  • Curious as to how you worked out this was the problem and changing the wait time solved the problem? – Markm0705 Jan 17 '18 at 06:22
  • 2
    Also found that this is a temporary solution and that after a restart the Sys.sleep returns to 0.5s - hoping next update of R will fix this issue – Markm0705 Jan 21 '18 at 22:53
  • 3
    I installed R 3.5 yesterday and the problem disappeared, also the `Sys.sleep(0.5)` line was removed, so I guess it's not needed anymore! – Gerhard Burger May 18 '18 at 05:54
  • 4
    You can also do this problematically e.g. `trace(utils:::unpackPkgZip, quote(Sys.sleep(2)), at = which(grepl("Sys.sleep", body(utils:::unpackPkgZip), fixed = TRUE)))` – David Arenburg Aug 19 '18 at 13:17
  • 1
    @DavidArenburg, nice! (I think you meant programmatically though :P) – Gerhard Burger Aug 29 '18 at 05:49
  • Is it possible to add @DavidArenburg's suggestion to the [RProfile initialization file](https://www.statmethods.net/interface/customizing.html)? – bonna Feb 18 '19 at 14:03
64

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

Sheldon
  • 1,215
  • 1
  • 15
  • 29
Tal Galili
  • 24,605
  • 44
  • 129
  • 187
  • 11
    Unfortunately the anitvirus setting is locked down as we are in a corporate setting – xiaodai Aug 30 '13 at 02:39
  • 2
    For users encountering this problem with Kaspersky, this site shows how to add an exclusion rule: http://support.kaspersky.com/11146 – ahfoss Aug 22 '16 at 17:07
  • Thanks! this was my problem. I turned off mcaffee, reinstalled my packages, loaded, and then turned it back on, and it worked! – Paul Dec 15 '16 at 17:52
  • @xiaodai have a look at my answer for a workaround for the antivirus corporate policy. – Sheldon May 30 '17 at 07:51
  • 1
    Hi Tal, I have a bit of a different problem which I highly appreciate your assistance with. My problem is that I can NOT load any `R` package using `library("packageName")` or `require("packageName")`. I get the following error: `Error: package or namespace load failed for ‘packageName’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): namespace ‘tibble’ 1.3.0 is already loaded, but >= 1.3.1 is required` – rnorouzian Dec 29 '17 at 02:33
41

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.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Sheldon
  • 1,215
  • 1
  • 15
  • 29
14

If you can just download the binary straight from CRAN. On windows when downloaded it will be a zip file. Now manually unzip this into the ..library/ folder of your R (.libPaths()). It worked for me on some packages.

xiaodai
  • 14,889
  • 18
  • 76
  • 140
7

I had this problem installing both swirl and dplyr. I am working on Windows 64-bit.

Warning: unable to move temporary installation

What I did is I accessed my temporary files on the C: drive, and opened my file extractor program and I extracted the files from the temp file in the C: drive to my R program files in the C: drive, by manually copying them. THIS WORKED FOR BOTH dpylr and swirl. Stoked!

Cheers,

Peach

Hanna Peach
  • 71
  • 1
  • 2
  • +1 This is the only solution that worked for me to install `swirl` on my windows 10 personal machine. All other solutions did not work for me. – GISHuman Mar 12 '18 at 16:46
2

I just met the same question, and the solution I found out was that you should install packages using the original R software (plus, you should choose the right mirror site, some of them are blocked). At first I used Rstudio to install packages and I got the same problem as you met. Hope this is helpful.

Yang
  • 29
  • 1
2

Can you not use the lib.loc parameter to only update packages in your personal library (in user)? There should be no way to enable a normal, non-augmented user to change files in the program files folder, so the only thing you can do (if you don't want to augment the user) is to have R not updating packages there.

A workaround is to avoid installing R in the program files folder (which may be more or less of a hack than just shifting the library location out of it, depending on your point of view).

Finally, if lib.loc doesn't cut it, you can look at the source code for update.packages and create your own customized version that will always avoid the common library location in program files.

Nick Sabbe
  • 11,684
  • 1
  • 43
  • 57
1

I have run into this error several times. In my own case, it is because our admins want us to use remote virtual disks (on Windows 7) for our files and everything is locked up tight as a drum. The only way I can use R packages is in a lib directory on that remote virtual disk. This wouldn't be a problem except that the network isn't always smooth and fast. Thus, when I need a package, especially one with several other packages in tow (e.g., MBESS), I either have to go through the get.packages() process multiple times until it finally finishes or make it IT's headache to do quick like the bunny for me. I can't always wait for IT.

Bryan
  • 225
  • 1
  • 11
1

I just went to the library folder (Windows XP) and deleted all fileXXXX folders. Reran the install an it is worked.

rocketScientist
  • 191
  • 1
  • 5
  • This worked for me, with similar issue with rJava. I manually created a folder in R/library called `R/library/rJava` and it worked perfectly. – JohnL_10 May 18 '17 at 06:16
0

I had the same problem. Since the issue seems to be the antivirus blocking the transf of a downloaded file, I tried a different download method in the install.packages and it worked.

For example:

install.packages("stringr", method = "curl")
Eduardo Leoni
  • 8,991
  • 6
  • 42
  • 49
0

You must go into the properties of the R folder and change the security parameters. You can enable the option to write and modify for all users.

0

The error : "unable to move temporary installation" is basically arising due to any of the antivirus running on your system. Try unzipping the downloaded file from the Temp folder into the default library path (you can get it by running .libPaths() in R session).

AnksG
  • 488
  • 4
  • 9
0

I'm using a MRAN and I was having so many versioning issues. Trying to work with tidyverse and ggplot2 and by upgrading to the latest version from Microsoft it solved all of my R-Studio versioning issues.

Version info:

Microsoft R Open 3.5.1
The enhanced R distribution from Microsoft
Default CRAN mirror snapshot taken on 2018-08-01.

Download Microsoft R Open 3.5.1

Paul Hegel
  • 61
  • 1
  • 6