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:

# installing/loading the package:
if(!require(installr)) { install.packages("installr"); require(installr)} #load / install+load installr
 
updateR(F, T, T, F, T, F, T) # install, move, update.package, quit R.

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)

If you like using the global library system, you can run the following in the old R:

# installing/loading the package:
if(!require(installr)) { install.packages("installr"); require(installr)} #load / install+load installr
 
updateR(F, T, F, F, F, F, T) # only install R (if there is a newer version), and quits it.

And then run the following in the new version of R:

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

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

  • Tyler Rinker

    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.

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

      Hi Tyler,

      Thank you for your kind words :)

      I would love to see this adapted for other OS’s, and/or other packages. If you come across packages which might benefit from it – feel invited to let me know :)

      Cheers,
      Tal

  • http://twitter.com/hlynsson Hans Róbert Hlynsson

    I use a library folder placed in My Documents and referenced in $HOME/.RProfile and the update process is just: Install new R. Done, nothing else to be done.

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

      Hi Hans,
      What OS do you use?
      And how does R know to read the .RProfile, if it was just installed?

      Cheers,
      Tal

      • http://twitter.com/hlynsson Hans Róbert Hlynsson

        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.

        • http://twitter.com/hlynsson Hans Róbert Hlynsson

          As Per: http://cran.r-project.org/doc/manuals/r-release/R-admin.html#Managing-libraries you can also set an environment variable to do this.

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

          Hi Hans,

          o.k, several things:

          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.

          With regards,
          Tal

  • duk

    I have a problem…. “Warning in install.packages :
    package ‘installr’ is not available (for R version 2.15.2)”

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

      Hi Duk, this is likely because it hasn’t reached your CRAN mirror yet. You can either try again, or switch to a different mirror.

      I’d be happy to hear if this has helped or not.

      • duk

        HI!
        I’ve installed package from file and it’s working.

        Great job, thanks.

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

          I’m glad it worked out :)

          Cheers,
          Tal

  • AC

    This is great, thank you—however, I get this error message:

    > if(!require(installr)) { install.packages(“installr”); require(installr)} #load / install+load installr

    Loading required package: installr

    Warning message:

    package ‘installr’ was built under R version 2.15.3

    > updateR() # 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.1

    And the latest R version is: 2.15.3

    Error in !install_R : ‘install_R’ is missing

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

      Hi AC,
      This is indeed a bug, thanks for catching it.

      Could you please try this again by typing:
      updateR(install_R = TRUE)
      And let me know if this time it works fine for you?

      I’ve fixed the bug in the devel version:
      https://github.com/talgalili/installr/commit/3baaf508f617a4015ee59ea543d133e288c3fe5c
      And the next time I’ll update the package to CRAN, there would not be this problem.

      With regards,
      Tal

      • JC

        Hi Tall,
        typing (install_R=TRUE) instead of (“install_R=TRUE”), now it works
        Regards

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

          Great :)

      • AC

        Works great now, Tal. Thanks for creating this package/function!

        AC

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

          My pleasure AC :)

          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.

          In short, I think this will be even easier in future updates.

          • AC

            nice! thank you!!

  • JC

    Hi,

    I get the following message

    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

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

      Hi JC,

      Please try again without the quotes:
      updateR(install_R = TRUE)

      (I’ll fix the blog post too)

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

        update: notice that you can now use
        updateR()
        And it would just ask you if you wish to update R (if a newer version exists)

  • Charles Cara

    This is a brilliant idea. Have you thought of trying to get this added to R-Studio?

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

      Hi Charles,
      Thank you :)

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

      With regards,
      Tal

  • AC

    Hi Tal,

    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.

    Thanks,

    AC

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

      Hi AC,
      That is a good idea, which I’ve considered on adding, but wasn’t sure people would use it.

      Since you mentioned it, I will add it to the “TODO” list, and update on this blog if/when it is done :)

      With regards,
      Tal

  • Farrel Buchinsky

    Dear Tal

    I like it. Nice idea. Is there a way to copy/move Rprofile.site from one installation to the next such as “C:Program FilesRR-2.15.2etcRprofile.site” to “C:Program FilesRR-2.15.3etcRprofile.site”?

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

      Hello dear Farrel,
      I’m happy you like it :)

      I will add this to the suggestions on my TODO list and will look into implementing it in future releases.

      With regards,
      Tal

      • Farrel Buchinsky

        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.

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

          Hi Farrel,
          I agree.

          But:
          1) I don’t think it would cause problems in copying it. and
          2) I generally encourage people to NOT install R on the C directory in Windows 7 (if a D: drive is available)

          Cheers,
          Tal

  • Pingback: Updating R (on Windows) through a menu-bar: installr 0.9 released on CRANR-statistics blog | R-statistics blog()

  • Eric

    How do you make installr copy your packages when they are in “C:Usersnot-admin-userDocumentsRwin-library3.0″

    to 3.0.1

    Is installr only intended for admin use?

    Thankd

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

      Hi Eric,

      installr is modular and offers procedures for several steps:

      1) checking for a new version of R

      2) installing a new version

      3) copying of packages from one folder to the other.

      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.

      Personally, I use the global library folder system (you can see more about this from this link: http://www.r-statistics.com/2011/04/how-to-upgrade-r-on-windows-7/

      )

      Does this help?

      With regards,
      Tal

  • Doug

    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.

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

      You’re welcome Doug,
      I am glad you found the package helpful. Thank you for saying a good word, you brought a smile to my face.

      Best,
      Tal

  • Guillermo C

    Could you please help me to install MPA Statistics into R.

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

      Hi Guillermo,
      Could you please send me relevant links for me to better understand your question?

  • Guest

    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?

  • Guest

    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???

  • Guest

    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?

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

      Hi guest,
      Which packages do you use which can not be used on 3.0.1?!

  • Networkdigger

    Cool! Thank you very much for this package!

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

      With pleasure, tell your friends about it :)

  • Yusuf Mohammed

    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.

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

      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.

      With regards,
      Tal

  • shruti marwaha

    Thanks Tal. This was very useful.

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

      Thank you very much Shruti :)

      Please also see other posts tagged with “installr”, as I have added more features, and nice menu-based navigation:

      http://www.r-statistics.com/tag/installr/

      With regards,

      Tal

  • Kay Cichini

    Love it!
    Thanks Tal!

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

      Thank you very much Kay :)

      Please also see other posts tagged with “installr”, as I have added more features, and nice menu-based navigation:

      http://www.r-statistics.com/tag/installr/

      With regards,

      Tal

  • Sree

    Tal
    First time user of your package and I cannot tell you how thankful I’m since I had over 400 packages to transfer between versions.
    Thank you once again!!

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

      Thank you very much Sree :)
      I’m glad to read that my package was helpful to you.
      With regards,
      Tal

  • Keona

    Thank you so much for this. I was lost without it!

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

      Thanks Keona,
      My pleasure.

  • peter2108

    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.

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

      Thank you for the kind words Peter.

      p.s: a newer version of installr (0.13.3) to get accepted to CRAN, which has a few more features which I hope to write about in the near future.

      With regards,
      Tal

  • Samaneh

    Thank you so much for your helpful message.

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

      My pleasure.

  • Pingback: Апдейт R | IT-Blog()

  • Bill Raynor

    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.

  • lcmercado

    Thanks Tal, it was very easy to upgrade to latest version along with packages.