Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning in install.packages: unable to move temporary installation

Tags:

r

rstudio

I've found a number of questions related to this warning when installing or updating packages in R/RStudio, but none seem to completely match my situation:

  • Corporate Windows 7 system, so no access to admin privileges
  • No way to make changes to McAfee Anti-Virus exceptions lists
  • R is fully installed in the user space C:\Users\[myname]\R
  • RStudio fully installed in userspace C\Users\[myname]\RStudio
  • no permission issues in either of the directories... I have full access control over them
  • Problem only started after installing R 3.4, but RStudio has randomly failing at start or hanging for a few months now
  • R_LIBS_USER added as user environment variable, pointing to right directory
  • .libPaths() show correct directories, both system and user
  • R version 3.4.2, RStudio version 1.0.153
  • Uninstalled both R and Rstudio and did a clean re-install of both
  • Tried trace(utils:::unpackPkgZip,edit = T) and edited Line 140 Sys.sleep(0.5) to Sys.sleep(2), which sometimes works temporarily but the edit won't stay put... resets to Sys.sleep(0.5) on every session restart
  • Happens in both RStudio and RGui
  • Any package larger than a few Kb gives the message:

    package ‘packagename’ successfully unpacked and MD5 sums checked
    Warning in install.packages :
      unable to move temporary installation ‘C:\Users\[myname]\R\win-library\3.4\file2b884fc37c13\packagename’ to ‘C:\Users\[myname]\R\win-library\3.4\packagename’
    

The packages are failing to install or update. So, my questions are:

  1. is there a way to avoid the problem altogether that doesn't require admin privileges or changes to the antivirus policies?
  2. is there a way to get the edit to unpackPkgZip to save permanently?

At this point, I'm stumped. I suspect it has something to do with the antivirus temporarily locking the file/directory after download, but I can't do anything about it from that end. The Sys.sleep(2) seems to do the trick, but I can't keep doing that before every package install or update and can't seem to get the edit to stay put.

like image 954
Scard Avatar asked Oct 05 '17 15:10

Scard


5 Answers

This was the only thing that worked for me on this issue (the uninstalling antivirus software didn't get me anywhere, unfortunately), so hopeful it works for you.

On Windows systems, sometimes installation of libraries may be running too fast, creating the error "unable to move temporary installation". Then the package is not found in the user library, because it hasn't been moved over...

To fix, try: trace(utils:::unpackPkgZip, edit=TRUE)

Then go to Line 140 in the code and change Sys.sleep(0.5) to Sys.sleep(2.5)

This is a nice longer term solution that does not require manual package moving, uninstalling software, replacing admin responsibilities, or individually routing packages to certain locations.

like image 193
kslayerr Avatar answered Nov 20 '22 17:11

kslayerr


My original reply is below, but I've subsequently found a better solution.

Execute the following line:

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

Note that there three colons in there, not two.

Then edit line 142, from Sys.sleep(0.5) to: Sys.sleep(2.0), and click to save the edit (the line number may vary slightly). Unfortunately this does not hold across R sessions, but it only takes 10 seconds to do this, and then you can install packages for the current session to your heart's content.

Original answer:

I ran into the same problem at work. I was able to use Sheldon's suggested approach, but as noted that can get tedious quickly. As an alternative, I found I could go to the location of the downloaded zip file(s) in my temp directory (as reported by install.packages), unzip the file or files (there will be multiple zip files if there are dependent packages), and then move or copy all the unzipped directories straight into my R\win-library\3.4 directory. This isn't a whole lot of fun either, but I find it to be less painful than stepping through the debugger, per Sheldon's method, especially when multiple dependencies are involved and also have to be installed.

like image 12
JeffR Avatar answered Nov 20 '22 18:11

JeffR


If you cannot turn off your antivirus here is a workaround that I found that doesn't involve editing the unpackPkgZip file. 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.

If you want to make this change more permanent you can add the debug code into your Rprofile file, see here, but you'll still need to use step through the unzip function each time a package is installed.

like image 8
Sheldon Avatar answered Nov 20 '22 17:11

Sheldon


Got the same error - seems to be a company gp / access security problem.

It might also be worthwhile checking whether the folder it fails to write to has a Read Only structure (Right Click - Properties). This folder's address can be found by running: .libPaths()[1] in R.

An ad hoc solution to this problem is to unzip and store the downloaded (but not moved) packages using a piece of R code below. You will get an error stating where the binary packages are located (something like: C:/Users/....AppData/...)

Now you can simply unzip the files from here to your .libPaths() location

zipF <- list.files("C:/Users/<YOURNAMEHERE>/AppData/Local/Temp/Rtmp4Apz6Z/downloaded_packages", full.names = TRUE)
outDir <- .libPaths()[1]

for(i in 1: length(zipF)) {
unzip(zipF[i],exdir=outDir)
}

A more general solution will still be extremely worthwhile, as this is unfortunately a common problem when updating R on Windows.

like image 5
Nick Avatar answered Nov 20 '22 17:11

Nick


We've had the same problem at my workplace, and one of my coworkers discovered a great workaround. Unfortunately it's a temporary thing you'll need to do each time you install packages, rather than a permanent fix. We're running corporate Windows 8 (no admin privileges) with McAfee, and I've tested this in R 3.4.0-3.4.3.

Temporarily turning off McAfee's "On-Access Scan" feature (in Threat Prevention) solved this for us -- R packages now all install on the first try the way they're intended to. Here's detailed steps to turn that off:

  1. Right-click the McAfee icon in the notification area at the right of your taskbar, and select McAfee Endpoint Security.
  2. Click on Threat Prevention. This opens up a screen where you should see categories such as "Access Protection", "Exploit Prevention", and "On-Access Scan".
  3. Un-check "Enable On-Access Scan", and then click Apply. (NB: it's easy to forget to click Apply, but it's essential)

Once you've installed your packages, it's best to repeat the process to turn On-Access Scan back on.

like image 4
dnidz Avatar answered Nov 20 '22 18:11

dnidz