__Update:__ This post has a follow-up for how to upgrade R on windows 7 explaining how to deal with permission issues.

### Background – how I heard that there is more then one way to upgrade R

If you didn’t hear it by now – R 2.11.0 is out with a bunch of new features.

After Andrew Gelman recently lamented the lack of an easy upgrade process for R, a Stackoverflow thread (by JD Long) invited R users to share their strategies for easily upgrading R.

### Upgrading strategy – moving to a global R library

In that thread, Dirk Eddelbuettel suggested another idea for upgrading R. His idea is of using a folder for R’s packages which is **outside **the standard directory tree of the installation (a different strategy then the one offered on the R FAQ).

The idea of this upgrading strategy is to save us steps in upgrading. So when you wish to upgrade R, instead of doing the following three steps:

- download new R and install
- copy the “library” content from the old R to the new R
- upgrade all of the packages (in the library folder) to the new version of R.

You could instead just have steps 1 and 3, and **skip step 2** (thus, saving us time…).

**For example**, under windows XP, you might have R installed on:

`C:\Program Files\R\R-2.11.0\`

But (in this alternative model for upgrading) you will have your packages library on a “global library folder” (global in the sense of independent of a specific R version):

`C:\Program Files\R\library`

So in order to use this strategy, you will need to do the following steps (all of them are performed in an R code provided later in the post)-

- In the OLD R installation (in the first time you move to the new system of managing the upgrade):
- Create a new global library folder (if it doesn’t exist)
- Copy to the new “global library folder” all of your packages from the old R installation
- After you move to this system – the steps 1 and 2 would
**not**need to be repeated. (hence the advantage)

- In the NEW R installation:
- Create a new global library folder (if it doesn’t exist – in case this is your first R installation)
- Premenantly point to the Global library folder whenever R starts
- (Optional) Delete from the “Global library folder” all the packages that already exist in the local library folder of the new R install (no need to have doubles)
- Update all packages. (notice that you picked a mirror where the packages are up-to-date, you sometimes need to choose another mirror)

Thanks to help from Dirk, David Winsemius and Uwe Ligges, I was able to write the following R code to perform all the tasks I described

So first you will need to run the following code:

### Code for upgrading R – only two lines for each R installation (old/new)

The code to perform all of the steps described above is available here, and can be accessed from within R using “source”.

In order to move your R upgrade to the new (simpler) system (assuming you already use R, and that it is your first time moving to the new system), do the following:

1) Download and install the new version of R

2) Open your old R and run –

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

(wait until it finishes)

3) Open your new R and run

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

(wait until it finishes)

Once you do this, then from now on, whenever you will upgrade to a new R in the future, all you will need to do are the following TWO (instead of three) steps:

1) Download and install the new version of R

2) Open your new R and run

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

(wait until it finishes)

And that is it.

__Update:__ This post has a follow-up for how to upgrade R on windows 7 explaining how to deal with permission issues.

Pingback: How to upgrade R on windows 7 | R-statistics blog

Pingback: The R-Podcast Episode 5: Basic Package Management » The R-Podcast

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

Pingback: Update R version | christopherdardis

Pingback: R 3.0.2 and RStudio 0.9.8 are released! | R-statistics blog

Pingback: R 3.0.3 is released | R-statistics blog

Pingback: R 3.1.0 is released! | R-statistics blog