28

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.

JSCard
  • 883
  • 2
  • 8
  • 14
  • 1
    `trace` is for interactive debugging, if you want to make changes permanent you'll have to change the package source files - [see the answer to this question](https://stackoverflow.com/questions/34800331/r-modify-and-rebuild-package) for how to do this - It's not something I've done myself. – Tom Newton Oct 12 '17 at 14:41
  • 1
    @TomNewton - Ah. Thank you. I should have realized that, but figured the "Save" button on trace would actually save to the package (why have one otherwise?). I'll take a look at package editing per the link and see if that looks feasible for me to do. – JSCard Oct 12 '17 at 15:00
  • Yes, I can see why that is misleading, perhaps "Apply" would be better. It looks fairly straightforward, if you do have success it's worth posting as an answer here for future reference. – Tom Newton Oct 12 '17 at 15:08

11 Answers11

36

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.

kslayerr
  • 819
  • 1
  • 11
  • 21
  • 3
    That's what I've been doing, and it (usually) works. Of course, you also have to remember to do it again if you restart your R session for any reason! – JSCard Mar 13 '18 at 15:53
  • 1
    Looking at this six months after it was posted. Had the same problem. This resolved my problem easily. – Jarom Apr 25 '18 at 14:10
12

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.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
JeffR
  • 524
  • 3
  • 10
8

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.

Sheldon
  • 1,215
  • 1
  • 15
  • 29
  • I ran across that, too. Reasonable hack if you're installing or updating one or two... more than that gets tedious, especially when there are numerous dependencies or installing a task view or anything from the bioconductor sources. – JSCard Nov 16 '17 at 13:11
  • Yes, I agree. I'm not sure if there is a way to automatically step through the code in debug mode that is slow enough to allow this fix to work. I'll see what I can find. I'm afraid that this is an issue that either R or McAfee will need to fix as I have seen it become more prevalent over the past months. – Sheldon Nov 20 '17 at 09:15
5

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.

Nick
  • 3,262
  • 30
  • 44
4

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.

dnidz
  • 183
  • 1
  • 2
  • 8
  • I'll give that a try. We use McAfee as well. A lot easier than the traceutils workaround. – JSCard Mar 06 '18 at 17:51
  • 1
    No go... with our system, we can only view the status and logs. No way to temporarily disable On-Access Scan. back to the `trace(utils:::unpackPkgZip,edit = T)` workaround... – JSCard Mar 13 '18 at 15:50
2

I fixed my instance of this problem (Windows 7) by removing the 'Read-Only' attribute of the folder R was trying to move stuff to.

I went to the Run command from the Start menu in Windows (7) and typed attrib -r +s drive:\\

Note that just right clicking the folder and trying to change properties didn't take, as per this link from Microsoft: https://support.microsoft.com/en-us/help/326549/you-cannot-view-or-change-the-read-only-or-the-system-attributes-of-fo

Hope that helps someone.

I hope this change doesn't screw me in other ways.

DavidE
  • 21
  • 1
  • Unfortunately, this isn't a permissions issue... it's an internal timeout that's kicking in as the antivirus scans the downloaded file, which locks it from being moved. – JSCard Feb 28 '18 at 21:26
1

This was the error message that was spit out for me:

package ‘mlogit’ successfully unpacked and MD5 sums checked
Warning in install.packages :
unable to move temporary installation ‘C:\Users\E\Documents\R\win-
library\3.4\file9ec6cfb5e40\mlogit’ to ‘C:\Users\E\Documents\R\win-
library\3.4\mlogit’

The downloaded binary packages are in
C:\Users\E\AppData\Local\Temp\RtmpS0uNDm\downloaded_packages

What I did was went to where the package was downloaded (C:\Users\E\AppData\Local\Temp\RtmpS0uNDm\downloaded_packages) and then copied that zipped file to the desktop then used Winzip to unzip to my file directory where all the packages for R are stored (C:\Users\E\Documents\R\win-library\3.4). It now will load in R.

library("mlogit")
Loading required package: Formula
Loading required package: maxLik
Loading required package: miscTools
....

It worked well for me as it was the only package that was not downloading for some reason. Might not be helpful if you have to do this for every package.

EDennnis
  • 191
  • 1
  • 11
  • I'm usually dealing with a dozen or so packages, so this gets unwieldy fast. – JSCard Mar 06 '18 at 17:52
  • @Scared. I agree. Works well for one-off packages that don't seem to work rather than solving an overarching issue to package installation – EDennnis Mar 06 '18 at 20:27
1

I also found one solution if above solutions wouldn't work in corporate antivirus. First change the path of package installation use this command and execute in R:

install.packages('caTools','D:\\ML\\Tools\\Installed\\RPackages')

Now it will show a console's error that unable to move and the package is placed on to some location. just remember this location, we need this zip file for further operations.

Now use this command:

install.packages("D:/ML/Tools/Installed/RPackages/caTools_1.17.1.zip", repos = NULL, type = "win.binary", lib="D:/ML/Tools/Installed/R-3.4.3/library") 
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Vikalp Jain
  • 85
  • 1
  • 7
1

I struggled with the same issue. For me (on Windows 10), the issue was using MalwareBytes (Premium trial). I uninstalled it and went back to using Windows Defender, and the issue was resolved. Perhaps if more time, I can find out how to create an exception and/or file checking delay for MalwareBytes (i.e., which is a pretty good program), but the user-guide (https://www.malwarebytes.com/pdf/guides/Malwarebytes-User-Guide.pdf) is unclear on this.

jrdunson
  • 301
  • 1
  • 3
  • 6
1

Extending the Sys.sleep value to 3.5 on line 142 in the unpackPkgZip function works manually via

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

However, it can also be done programmatically by running the following before install.packages:

localUnpackPkgZip <- utils:::unpackPkgZip
body(localUnpackPkgZip)[[14]][[4]][[4]][[4]][[3]][[3]][[2]][[2]] <- substitute(3.5)
assignInNamespace("unpackPkgZip", localUnpackPkgZip, "utils")

This must be run every time you have a new session. You can run it multiple times in the same session without issue.

modelDBA
  • 176
  • 1
  • 8
0

If you run the below statement right before the install.packages expression then it should install the package:

trace("unpackPkgZip", where=asNamespace("utils"), quote(Sys.sleep(2.5)), at=14L, print=FALSE)
Mohammad Usman
  • 37,952
  • 20
  • 92
  • 95