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("https://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).

134 thoughts on “Updating R from R (on Windows) – using the {installr} package”

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

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

      1. 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. 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:
          https://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

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

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

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

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

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

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

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

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

  6. 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”?

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

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

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

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

    1. 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: https://www.r-statistics.com/2011/04/how-to-upgrade-r-on-windows-7/

      )

      Does this help?

      With regards,
      Tal

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

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

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

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

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

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

  13. 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!!

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

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

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

  16. Great job!!

    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.

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

  17. Wow! I have to work in Windows now, and your package has made my life sooo much easier!

    thank you very much
    Jarek

  18. Hello Tal,

    I just installed Fire Safety, only to discover to my utter dismay that some packages did not update and I cannot reinstall them, cos I get a warning that the package is not available in R 3.2.2.

    What do you suggest I do?

  19. Hello,

    I consider an update from version 3.1.0 to 3.2.3, which will be released next week on December 10, 2015.
    Long time ago, I installed R, 64 bits only, in folder “C:/Code/R-310/”.
    system.PATH() detects it properly (for clarity, I replaced double anti-slashs by /) :
    “C:/Code/Rtools/bin”
    “C:/Code/Rtools/gcc-4.6.3/bin”
    “C:/Code/R-310/bin/x64”
    “C:/Code/R-310/share/texmf/tex/latex”
    “C:/Program Files/MiKTeX29/miktex/bin/x64”
    “C:/MinGW/bin”
    “C:/MinGW/lib”

    Questions are :
    1/ where updateR will install the new version 3.2.2 ?
    – with default options ?
    – by using updateR(fast = TRUE) ?
    2/ Can I force the folder “C:/Code/R-322/” ?
    3/ I will have also to update RTools ? Is a dual install (RTools31, RTools33) possible or not ? How does installr handle it ?

    Thanks. Patrice

    1. Hi Patrice,
      If you just run:
      installr()
      It will download and allow you to run the installer wherever you want.
      If you want to also copy the packages and update them you will need to use
      updateR()

      It should work fine as long as you don’t install your R version in the same folder, but in the folder above it (i.e.: code – which is what you seem to want to do).

      Regarding rtools – I have no clue.
      You can run
      install.rtools()
      to download it, and run the installer, and see if it works.

      Best,
      Tal

  20. I have just updated my R from version 3.2.2 to 3.2.3. I want to remove the old version. How can I do that without problems?

    1. If you installed R on a different folder, and copied all the packages – then you can use the uninstall wizard from Windows to remove the older version.
      There is also a file called “unins000.exe” in the folder of the old R installation which you can double click to uninstall R.

  21. tried to update R on Linux Centos7 but failed due to path issue. Any solution?

    [root]# sudo su – -c “R -e \”installr::updateR()\”
    Error in file(con r ) cannot open the connection
    Calls: -> check.for.updates.R -> readLines -> file
    In addition: Warning message:
    In get.installed.R.folders() :
    Could not find any R installation on your system. (You might have installed your R version on ‘c:\R’ without sub folders…
    Execution halted

    1. Hi Ryo,
      installr only works for Windows.
      If you’ll find a good resource on upgrading R for linux, it might help adding it to installr.

      Best,
      Tal

  22. Hi Tal,

    I am upgrading my R 2.15.1. My first problem while was using upgradeR() is the error message “Error in file(con, “r”) : cannot open the connection”. Then I used setInternet2(TRUE) to fix it. After that, I got the error message “Error in strsplit(version_with_dots, “\\.”)[[1]] : subscript out of bounds”. I looked your post, and tried to use the devtools::install_github(‘talgalili/installr’) to upgrade the installr. However, it fails and the message indicates that the installr requires the dependency ‘curl’, but “package ‘curl’ is not available (for R version 2.15.1)”. Could you please advice how to fix it so that I can upgrade the R 2.15.1? Thanks,

    1. Just to let everyone know this was fixed in installr version 0.17.7
      You can always get the latest version of installr using devtools:
      devtools::install_github(‘talgalili/installr’)

      Tal

  23. When trying to run udateR() I get this error message: Error in loadNamespace(name) : there is no package called ‘stringr’

    Thanks
    Robin

  24. Hello Tal, it is nor working for me. After 1) setInternet2(TRUE), 2) library(installr) und 3) updateR() I get the message use setIntenet2(TRUE). My R-version is 3.1.3 and use internet explorer per default. Thank you! Best regards, Sergio.

  25. hello Sir,

    I am a new user of R.I want to install Rcpp package but problem occurred as unable to move….please help me.

    package ‘Rcpp’ successfully unpacked and MD5 sums checked
    Warning: unable to move temporary installation ‘C:\Users\Admin\Documents\R\win-library\3.4\file15bc1b10b0a\Rcpp’ to ‘C:\Users\Admin\Documents\R\win-library\3.4\Rcpp’

  26. installed R using install.R()
    now i am not able to find my user library packages in R studio including installr
    can you please tell me how to retrieve back all the packages which i was using?

  27. Hi Tal,

    I do can installr package but when type library(installr), RStudio doesnt find the package. Also, cant use updater() nor updateR(install_R=TRUE). Any clue?

    1. Hi Tal!

      Thank you very much for your great package! I’m using your package “installr” and the “updateR()” function wihin the R Console in Windows 7 and Windows 10.

      During the update process of “updateR()” when choosing to update the packages in the newely installed R, do the packages in the ‘User Library’ of the old R Version also get updated (which have to be copied manually to the User Library of the new R Version), besides the ones of the ‘Site Library’ automatically copied/moved by the update process?

      Thanks for your Feedback!
      Best, Gregor

  28. Hi Tal!

    Thank you very much for your great package! I use your package “installr” with “updateR()” within the R Console on Windows 7 and 10.

    During the update process of “updateR()” do the packages of the ‘User Library’ (which have to be copied manually into the new ‘User Library’ of the newely installed R Version) also get updated like the ones in the ‘Site Library’ automatically copied/moved to the new R Version by the update process?

    Thanks for your feedback!
    Best, Gregor

  29. This is all fine and dandy, except “IT DON’T WORK”. What do we do when we get
    Error in library(installr) : there is no package called ‘installr’

    1. This package is for Windows. If you’re on mac, try the updateR package. And if you can’t find the package try changing your CRAN mirror.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.