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("http://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("http://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("http://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.0\etc\Renviron.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 files\R” 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 Files\R\R-2.13.0\library\file70669f\***’ to ‘C:\Program Files\R\R-2.13.0\library\***’

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…

  • http://decisionstats.com Ajay

    more ‘from’ files than ‘to’ files is the error i get on my windows 7

    • http://www.talgalili.com Tal Galili

      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

  • Pingback: Download R 2.13.0 for Windows - Quantitative Finance -

  • http://decisionstats.com Ajay

    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(“http://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

    • http://www.talgalili.com Tal Galili

      Hi Ajay,
      What is the exact path of your R installation?

    • http://www.talgalili.com Tal Galili

      Hi Ajay,
      Please try again using the following:

      Old.R.RunMe(global.library.folder = “C:\\Program Files\\R\\library”)

  • http://decisionstats.com Ajay

    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”

    • http://www.talgalili.com Tal Galili

      Hi Ajay,
      What is your output when running:

      R.home()

      ?

  • http://decisionstats.com Ajay

    > R.home()
    [1] “C:\\PROGRA~1\\R\\R-212~1.1″

    • http://www.talgalili.com Tal Galili

      Thanks Ajay. I can’t seem to reproduce your error. If you feel like opening up the code and figuring out the bug, it would be nice.
      Thanks,
      Tal

    • http://www.talgalili.com Tal Galili

      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

  • Pingback: Upgrading R and R Packages – Part 2 « kRistens.blog

  • Wes

    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

    • http://www.talgalili.com Tal Galili

      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

      • Wes

        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

  • Betula

    Hi Tal,

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

    Betula

    • http://www.r-statistics.com/ Tal Galili

      Hi Betula – I am happy it worked/helped :)

      Cheers,
      Tal

  • Pingback: Updating R from R (on Windows) – using the {installr} packageR-statistics blog | R-statistics blog