R-statistics blog » R, and kindly contributed to Want to share your content on R-bloggers? [This article was first published on, and kindly contributed to R-bloggers ]. (You can report issue about the content on this page here Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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. 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:

1 2 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):

1 2 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.

1 2 3 4 5 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.

It is advisable to restart your Rgui in order to have the changes (for example, file permission changes) take effect. Also, sometimes you need to install the same package twice before the installation “catches” (e.g: that you’d get the “package ‘***’ successfully unpacked and MD5 sums checked” massage).

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…