How to upgrade R on windows 7

Background – time to upgrade to R 2.13.0

The news of the new release of R 2.13.0 is out, and the R blogosphere is buzzing. Bloggers posting excitedly about the new R compiler package that brings with it the hope to speed up our R code with up to 4 times improvement and even a JIT compiler for R. So it is time to upgrade, and bloggers are here to help. Some wrote how to upgrade R on Linux and mac OSX (based on posts by Paolo). And it is now my turn, with suggestions on how to upgrade R on windows 7.

Upgrading R on windows – the two strategies

The classic description of how to upgrade R can be found in the R project FAQ page (and also the FAQ on how to install R on windows)

There are basically two strategies for R upgrading on windows. The first is to install a new R version and copy paste all the packages to the new R installation folder. The second is to have a global R package folder, each time synced to the most current R installation (thus saving us the time of copying the package library each we upgrade R).

I described the second strategy in detail in a post I wrote a year ago titled: “How to upgrade R on windows XP – another strategy” which explains how to upgrade R using the simple two-liner code:

source("https://www.r-statistics.com/wp-content/uploads/2010/04/upgrading-R-on-windows.r.txt")
New.R.RunMe()

p.s: If this is the first time you are upgrading R using this method, then first run the following two lines on your old R installation (before running the above code in the new R intallation):

source("https://www.r-statistics.com/wp-content/uploads/2010/04/upgrading-R-on-windows.r.txt")
Old.R.RunMe()

The above code should be enough.  However, there are some common pitfalls you might encounter when upgrading R on windows 7, bellow I outline the ones I know about, and how they can be solved.

upgrade R on windows 7 – the issues

Ideally, we would simply run the code above and go on doing our statistics.

But for windows 7 users there are several common issues when upgrading to a new version of R (compared to when upgrading R in windows XP).

Issue 1 – folder location when upgrading from 32 bit to a 64 bit R version

The first issue is that the folder in which R is installed might be different if you have installed the 32 bit version on win 7 and now started using the 64 bit version, in which case you will need to run the following commands (notice the use of the “global.library.folder” paramater), I here assume you’ve installed R on D:R.

source("https://www.r-statistics.com/wp-content/uploads/2010/04/upgrading-R-on-windows.r.txt")
# in the old R
Old.R.RunMe(global.library.folder = "D:\R\library")
# in the new R
New.R.RunMe(global.library.folder = "D:\R\library")

Issue 2 – folder permissions

The second issue is problem with permissions. The default permissions of a regular user on windows 7 won’t let you create folders and files under the “c:program files” directory (and, if I am not mistaken, for some other directories as well).   The result of this problem is that running the upgrade code I provided above, will often result with an error similar to this one:

[1] “The path to the Global library ( d:\R\library\ ) Didn’t exist – and was now created.”
Error in file(file, ifelse(append, “a”, “w”)) :
cannot open the connection
In addition: Warning messages:
1: In dir.create(global.library.folder) : ‘library’ already exists
2: In dir.create(global.library.folder) :
cannot create dir ‘library’, reason ‘No error’
3: In file(file, ifelse(append, “a”, “w”)) :
cannot open file ‘D:/R/R-213~1.0etcRenviron.site’: Permission denied

There are three solutions to this, the best one (I believe) is number 2 (maybe also combined with number 3):

Solution 1: (which is easier to do, but I like less these days) is to run R with administrator privileges by following these steps:(My thanks goes to superuser):

  • Right click on the R shortcut
  • Click on Properties
  • Select the Compatibility tab
  • At the bottom click “Change settings for all users”
  • Again at the bottom select to “Run this program as an administrator”

The downside of this method is that every time you will start up R, you will get a nagging pop-up window asking you if you want to grant admin privileges to R, not a fun thing to deal with on a day to day basis.  Also, some other programs might have a hard time “doing things to” R, if it is run as administrator while they are not.

Solution 2 (editors pick):  Change (grant) your own user permissions to the relevant R folders (for example: “D:R”). In order to do this you can simply follow the steps described here.

Solution 3: Install R in something like “D:R” instead of “C:program filesR” so to avoid permission problems.

Issue 3 – antivirus file access restrictions

One of the possible error massage you might come across when trying to upgrade (or install) your R packages is the following:

massage:
package ‘***’ successfully unpacked and MD5 sums checked
Warning: unable to move temporary installation ‘C:Program FilesRR-2.13.0libraryfile70669f***’ to ‘C:Program FilesRR-2.13.0library***’

After (too much) pocking around, I suspect that the source of this error was two things. The first is my antivirus software. It appears that the “real time file system protection” was blocking R from copying the files between folders once they were downloaded. The second is the permission issues discussed above.
The solution is to add the R directory path to the exception list in the antivirus software + fixing the user permission as discussed above in “solution 2”.
p.s: I suspect that the reason this error happens with only some of the packages and not all of them is because of the *.dll the error prune packages have in them. But I am not sure of that.
Update: After disabling the antivirus while updating, I still found that I need to use the update function twice until it is able to properly install the package. Another potential reason for this problem was posted in 2005 by Sean O’Riordain suggesting that:

This is just an FYI documenting a conflict between R and
Google-Desktop. The solution was to click on the Google-Desktop icon
in the systray and click on “Pause Indexing”. I also temporarily
suspended anti-virus scanning before successfully
install.packages(“VR”) many times without getting an error message.

I was getting an intermittant failure when I tried to install a
package or update a package under Win-XP-Pro-sp2.

There is 5gb of free space on the drive and I’m an admistrator on this
machine and most times (but not every time) I tried to
upgrade.packages() or install.packages() I got the following error
message “unable to move temporary installation” message.

It appears to be a file-locking issue with the Google-Desktop search –
ie. during the few seconds that install.packages() creates a fileNNNN
directory tree, google-desktop starts reading these files and then
prevents this tree from being moved to its correct place under
library

cheers,
Sean

 

I wish R will have an “automatic update” mechanism one day, but until then I hope the above code will make your R upgrading experience a tiny bit easier…

25 thoughts on “How to upgrade R on windows 7”

    1. Hi Ajay,
      I didn’t follow your comment.
      Are you remarking on a grammatical mistake I made? (If so, please quote the entire sentence)
      Or of a problem with upgrading? (in which case, a more detailed error massage will help)

      Cheers,
      Tal

  1. sorry for not pasting it clearly. here is the complete R code and error I am getting.

    R version 2.12.1 (2010-12-16)
    Copyright (C) 2010 The R Foundation for Statistical Computing
    ISBN 3-900051-07-0
    Platform: i386-pc-mingw32/i386 (32-bit)

    R is free software and comes with ABSOLUTELY NO WARRANTY.
    You are welcome to redistribute it under certain conditions.
    Type ‘license()’ or ‘licence()’ for distribution details.

    Natural language support but running in an English locale

    R is a collaborative project with many contributors.
    Type ‘contributors()’ for more information and
    ‘citation()’ on how to cite R or R packages in publications.

    Type ‘demo()’ for some demos, ‘help()’ for on-line help, or
    ‘help.start()’ for an HTML browser interface to help.
    Type ‘q()’ to quit R.

    > source(“https://www.r-statistics.com/wp-content/uploads/2010/04/upgrading-R-on-windows.r.txt”)
    > # in the old R
    > Old.R.RunMe(global.library.folder = “C:\Program Files (x86)\R\library”)
    [1] “The path: C:\Program Files (x86)\R\library Didn’t exist – and was now created.”
    [1] “———————–”
    [1] “I am now copying packages from old library folder to:”
    [1] “C:\Program Files (x86)\R\library”
    [1] “———————–”
    Error in file.copy(from = list.of.dirs.in.lib, to = global.library.folder, :
    more ‘from’ files than ‘to’ files

  2. different error.

    > #Old.R.RunMe(global.library.folder = “C:\Program Files\R\library”)
    > Old.R.RunMe(global.library.folder = “C:\Program Files\R\library”)
    [1] “The path: C:\Program Files\R\library Didn’t exist – and was now created.”
    [1] “———————–”
    [1] “I am now copying packages from old library folder to:”
    [1] “C:\Program Files\R\library”
    [1] “———————–”
    Error in file.copy(from = list.of.dirs.in.lib, to = global.library.folder, :
    more ‘from’ files than ‘to’ files
    > pwd()
    Error: could not find function “pwd”
    > getwd()
    [1] “C:/Users/KUs/Documents”
    > ls()
    [1] “New.R.RunMe” “Old.R.RunMe”

    1. Hi Ajay,
      After many playing around, I believe now that the reason could be that you have R installed on c:program files
      Try installing R on a folder outside the program files (preferred even to have it on a different hard drive)

      Tal

  3. Hi,
    Have you ever seen an error like this:

    > update.packages(ask=’graphics’)
    Error in readRDS(file) : error reading from connection
    > .libPaths()
    [1] “C:/Program Files/R/library”
    [2] “C:/Users/Wesley/Documents/R/win-library/2.13”
    [3] “C:/Program Files/R/R-2.13.0/library”

    If I remove the Renviron.site file, it’ll update like normal. But, of course it doesn’t find the extra library folder. I don’t know what’s happened to change things since it’s always worked fine before.

    Wes

    1. Hi Wes,

      I suspect that the extra folder you see ([2] “C:/Users/Wesley/Documents/R/win-library/2.13”) is because of installing something like RStudio, and running this code through it, am I correct?
      If so – I’d appreciate if you could contact them at support: http://support.rstudio.org/ and let me know if they could figure it out.

      Cheers,
      Tal

      1. Thanks Tal,

        I have suspected RStudio, but it’ll do it even when I’ve uninstalled RStudio & did a fresh install of R. I’ve gone back and played around some more and this is what I’m seeing.

        I remove the library folder generated by your function for the R folder and R will update fine. I can run your script again, create a new library folder and everything works fine. If I take one of the package folders out of the old library folder and put it in the new folder, I get the same error. But, if I take one of the old folder & place it in R’s library folder, then I get the error again.

        I’ve tried it with a few different packages and in both library folders. There must be something about my old library that’s giving R a headache. I’ll probably just have to reinstall them.

        Thanks again,

        Wes

  4. Hi Tal,

    Thanks for this! It worked like a charm when upgrading to
    2.14, and had no hassle with Tinn-R either.

    Betula

  5. Initially, got a problem installing package Rccp. My solution is ‘setting the library folder in the exclusion folder in the antivirus software’ .. I am using kapersky. only after that, manage to install Rccp package.

  6. The IT department couldn’t download on to my laptop as it came up with an exploit warning from the anti-virus software that couldn’t be overwritten.

Leave a Reply to Tal GaliliCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.