Updating R from R (on Windows) – using the {installr} package

Upgrading R on Windows is not easy. While the R FAQ offer guidelines, some users may prefer to simply run a command in order to upgrade their R to the latest version. That is what the new {installr} package is all about.

The {installr} package offers a set of R functions for the installation and updating of software (currently, only on Windows OS), with a special focus on R itself. To update R, you can simply run the following code:

# installing/loading the package:if(!require(installr)){install.packages("installr");require(installr)}#load / install+load installr# using the package:
updateR()# this will start the updating process of your R installation. It will check for newer versions, and if one is available, will guide you through the decisions you'd need to make.

Running this function will perform the following steps:

Check what is the latest R version. If the current installed R version is up-to-date, the function ends (and returns FALSE)

If a newer version of R is available, you will be asked if to review the NEWS of the latest R version – in order to decide if to install the
newest R or not.

If you wish it – the function will download and install the latest R version. (you will need to press the "next" buttons on your own)

Once the installation is done, you should press "any-key", and the function will proceed with copying all of your packages from your old (well, current) R installation, into your newer R installation.

You can then erase all of the packages in your old R installation.

After your packages are moved (and the old ones possibly erased), you will get the option to update all of your packages in the new version of R.

Lastely – you can open the new Rgui and close the current session of your old R. (This is a bit buggy in version 0.8, but has been fixed in version 0.8.1)

If you know you wish to upgrade R, and you want the packages moved (not copied, MOVED), you can simply run:

Since the various steps are broken into individual functions, you can also pick and choose what to run using the relevant function:

# installing/loading the package:if(!require(installr)){install.packages("installr");require(installr)}#load / install+load installr# step by step functions:
check.for.updates.R()# tells you if there is a new version of R or not.
install.R()# download and run the latest R installer
copy.packages.between.libraries()# copy your packages to the newest R installation from the one version before it (if ask=T, it will ask you between which two versions to perform the copying)

The {installr} package also offers functions for installing various other software on Windows. These functions include: install.pandoc (which was mentioned on this blog recently), install.git, install.Rtools, install.MikTeX, install.RStudio, and a general install.URL and install.packages.zip functions. You can see these further explained in the package’s Reference manual.

Feature requests, bug reports – and your help in improving the package

You can see the latest version of installr on github, where you can also submit bug reports (you may also just leave a comment in this post). Since this is my first R package, I might have (e.g: probably have) missed something here or there. So any comment on how to improve my code/documentation/R-fu, will be most welcomed (here or on github).

If this type of coding is fun/easy for you, you can help me improve this package on github. Cool new features I think may be added (by me or others) are:

Add an uninstall.R function – to remove the old R version.

Add more support for upgrading R for people who uses a global library for their packages.

Add support for Linux and Mac! This one I am less likely to do on my own – and would love to see someone else extend my code to other operation systems.

GUI – add a menu based option for running updateR. Something like help->”check for updates” would be great. (p.s: this idea came from Yihui Xie)

add even more install.software functions. If you have functions for which you’d like to be able to easily install them – just let me know and it could be included in future releases.

Thanks

Final note, I would like to thank the many people who have developed WONDERFUL tools for making R package development possible (and even somewhat fast), on Windows. These include Prof. Brian Ripley and Duncan Murdoch for Rtools, also Uwe Ligges for his work on CRAN, Hadley Wickham for devtools (in general, and for its documentation), Yihui Xie for roxygen2, JJ and others in the RStudio team for RStudio, the people behind git and github, and more. There are probably more things I can thank these people for, and many more people I should thank, but I can’t figure who you are probably (feel free to e-mail me, I appreciate you work even if it is not clear to me your are behind it).

This is terrific work I didn’t know existed. It would be awesome to see it extended to Mac and Linux as well (which is likely much easier). This would enable other packages to call your package to install programs easily or just direct the users to directly ger installr to install programs.

In this case I’m referencing Win7. It will by default look for $HOME/.Rprofile (C://Users/ME/My Documents/.Rprofile) if exists load it, else check for $R_HOME/etc/Rprofile.site etc. Only issue I had was creating the file, since you can’t in the Explorer (file can’t start with . sillyness), but you can from R’s file.create and then edit via Notepad(++). I use Ubuntu and Mac too with the same user owned library setup. Ubuntu upgrade via apt-get upgrade and Mac via normal installer. No need to migrate packages between versions.

1) The idea of using a global library folder (which you described), is indeed (in my view) a good one. In fact, that I wrote some code that will grantee it every time you upgrade your R system, please see:http://www.r-statistics.com/2011/04/how-to-upgrade-r-on-windows-7/
(it is based on the environment variable you mentioned in your next post)

2) I am not sure about using the (C://Users/ME/My Documents/.Rprofile) for this purpose. I can understand why it would work if you just start up R (since they always set the default working library to be my documents). However, for someone who uses RStudio projects (where the default working directory is different every time), I suspect in this case the .Rprofile will not be loaded first (although it is worth checking to make sure).

3) Regarding Ubuntu and Mac, if you’d be interested in helping to extend the code to these OSs, feel free to e-mail me, and I’ll be happy to work this out with you.

BTW, I’ve just update the package (on github, not yet on CRAN), so that all of this process will use window prompts (e.g: full GUI), instead of command line “yes/no”. And the package now adds a menu for “update R” when using the Rgui.

updateR(“install_R = TRUE”) # this will start the updating process of your R installation.
There is a newer version of R for you to download!
You are using R version: 2.15.2
And the latest R version is: 2.15.3
Error en !install_R : install_R’ esta perdido

I didn’t think of asking RStudio, it’s a good idea. I thought it would actually be nice to have it (eventually) added to R itself (though I imagine that if ever this were to happen, it would be done differently than the way I’ve implemented it in the package).

I am wondering if there is a way to automate this process of updating R (or adding a function to do so), e.g., some way to automatically run the updateR function above every few months?

This question is partially due to the fact that I will probably forget about this package and its utility (not because of its relevance, of course!) and some automated process will make sure I am being efficient when updating R.

One problem you may run into on Windows is that C:Program FilesRR-2.15.3etc is a protected location. Even when I want to manually edit it I have to open notepad application as an administrator and then open Rprofile.site otherwise Windows 8 does not allow me to save it.

The two later stages do require admin privileges. Also, the copying of packages assumes you wish to move them from the default library folder of the old R to the one of the new R. You can also only use the install.R() function and take care of the package folders on your own.

I am very new to R and installed v2.15.2 last year. Tried to install packages to it recentaly and it wouldn’t run and needed to update. Thank for putting this together. Took me a little time to work thru some issues, but was able to update to v3.0 done. Now I am working on getting my database setup. Thank You for putting this package together and providing support.

Hi Tal, Thank you for this wonderful package. The current latest version of R is 3.0.1. The one I have installed on my computer is 2.15.2. Is there a way to upgrade to 2.15.3 instead of the latest 3.0.1 using installr()

I want to to move to 2.15.3 becuase it seems like most of the packages I use are built for 2.15.3. I am not sure if there is enough package support for 3.0.1 or if if even matters?

Hi Tal, Thank you for this wonderful package. The current latest version of R is 3.0.1. The one I have installed on my computer is 2.15.2. Is there a way to upgrade to 2.15.3 instead of the latest 3.0.1 using installr()

I want to to move to 2.15.3 becuase it seems like most of the packages I use are built for 2.15.3. I am not sure if there is enough package support for 3.0.1 or if if even matters???

Hi Tal, Thank you for this wonderful package. The current latest version of R is 3.0.1. The one I have installed on my computer is 2.15.2. Is there a way to upgrade to 2.15.3 instead of the latest 3.0.1 using installr()

I want to to move to 2.15.3 becuase it seems like most of the packages I use are built for 2.15.3. I am not sure if there is enough package support for 3.0.1 or if if even matters?

Hi Tal, It is very interesting to know about the package.
I have R version 1.14.1 release (2011.12.22), recently I installed package(CAMAN) but it did not load in my system, do you think it is because I have an older R version? I wanted to upgrade the R version to the latest, but I am afraid my older self-written programs will not run successfully after the upgrade. Pls advice me accordingly. thank you.

Hello Yusuf,
Well, I am not sure if installr will work on R version 1.14.1 or not.
In your case I would suggest manually download and install the newer version of R, and whenever you would see you are missing a package you had to re-install it.

Please feel welcome to share with us if you have any insights regarding this upgrade.

Thank you for this Tal – really useful! I put off upgrading R because of the hassle! Now I can do ity easily. I was using RStudio on Windows7 64bit, and the process works fine. When the process asked me to open a new gui I said No, to quit R I said No, and then I quit RStudio manually.

Thanks for the package. It appears to have a wierd interaction with bioconductor packages, which causes the bioconductor package to get confused about the version. I used installr() to upgrade from 3.0.2 to 3.10. After that, the Bioconductor install script (biocLite) continually failed with version complaints.
I installed a clean version of 3.1.0 and biocLite worked just fine. I haven’t pursued it any further.

Two shortcomings (not bugs) I had, unless I made a mistake, was that the RProfile.site wasn’t copied from the previous version’s etc folder, and R Studio was still working with the previous version of R, but I’m guessing from other posts that the aim wasn’t extended towards R Studio yet.

Hi there,
Regarding RStudio – that depends on the way it is set for you. They have an option to work with a specific version of R, or with the latest version installed. If you choose the later, it should work fine.

Regarding RProfile.site, this is a feature in the installr version on github, it was not yet made public in CRAN. Which version of installr did you use?