potential solution for when anti-virus prevents moving a temporary installation

Moved from thread Unable to move temporary installation


Mara/R Community -

There are many people across our organization having the same issue. It does relate to the temporary file being locked by our enterprise anti-virus application when RStudio tries to move the package into the user's package directory. Changing the wait Sys.sleep time allows the anti-virus to do its scan and release the file for moving. This solution has worked for everyone who experiences this issue. How can we log this for developers to fix? I certainly do not expect to make RStudio slower by globally upping the Sys.sleep time in the application but the current work-around only works for the current session a user is in. Every time the RStudio app is started or a new session is spun up, the user has to employ this work-around. I would hope there would be a way we can permanently make this update to the Sys.sleep time through modifying a configuration file rather then taking this manual step every time.

Since this issue is being experienced by many Windows users across multiple organizations, is there any appetite to make this update/change?

1 Like

I'm not totally sure where in the stack the install.packages() Sys.sleep() time comes from — it's not dplyr-specific. So, this might be an IDE feature request.

If you’d like to submit this as a feature request, here's your starting point:
RStudio IDE Guide: Writing Good Feature Requests

I'll reach out to a couple people to make sure I'm not sending you in the wrong direction here.

3 Likes

If I'm following this correctly, it sounds like @bblake73's organization has been struggling with the phenomenon where install.packages() can fail on Windows because antivirus software interferes with the step where an installed package binary is moved from a temporary directory to its final location. And the current workaround (as described in the answers to this StackOverflow question) is to overwrite a hard-coded Sys.sleep() time, which of course is inconvenient, since this patch has to be applied anew each session. Have I got that right?

I think I can fill in some of the picture here. It looks like the Sys.sleep() call in question was part of an unexported helper function called utils:::unpackPkgZip. This helper function is only found in Windows-specific utils code, since it's used by the internal function that installs package binaries on Windows.

The hard-coded Sys.sleep() value was introduced back in the R 2.x era in an attempt to work around antivirus interference. However, as of R 3.5 (I think), a more sophisticated attempt to solve the antivirus problem was introduced. It was mentioned in this R-devel message, and this bit from the R 3.5.0 release notes seems to be related:

  • On Windows, file.rename() internally retries the operation in case of error to attempt to recover from possible anti-virus interference.

This seems to be an area of ongoing development in the R core, with further refinements added recently (for the curious, see here and here).

TL;DR

Getting back to your question :sweat_smile:, @bblake73:

  • The workaround involving patching Sys.sleep() will not work with R >= 3.5, since the Sys.sleep() call was replaced with a different approach to solving the antivirus interference problem
  • Hopefully the newer approach will work better! Are you able to test out updating to a newer version of R? I'd be curious to know whether you see any improvement in these package installation problems.
  • This is all part of core R functionality, so I'm afraid it's not something that the RStudio IDE can directly affect. Decisions about how to make install.packages() handle antivirus interference better are up to the R Core Development Team.
3 Likes

One more thought:

Are you overriding the Sys.sleep() value by hand, or are you using code like this?

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

(Disclaimer: from this StackOverflow answer which has no votes yet, and which I can't test myself! If it works for you, please go upvote the original contributor on SO :grinning:)

If you can get some version of the above working on your systems, you could at least put it in an .RProfile file so it gets run automatically for new sessions.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.