Update R using RStudio
Asked Answered
M

10

318

How can I update R via RStudio?

Memorandum answered 1/12, 2012 at 5:29 Comment(1)
The answers are inconsistent and it seems many things have changed since the Q's and the A's...Arrange
A
154

You install a new version of R from the official website.

RStudio should automatically start with the new version when you relaunch it.

In case you need to do it manually, in RStudio, go to :Tools -> options -> General.

Check @micstr's answer for a more detailed walkthrough.

Asbestosis answered 1/12, 2012 at 5:43 Comment(9)
RStudio detects this automatically... You only need to update the option if you want to use a different (previous, x32, x64) bit version.Wentletrap
@Brandon Bertelsen How? It never updates my R version. And the 'update' in the help menu is the update of RStudio only.Lorislorita
Outdated answer. You must restart RStudio after installing a new version of R. For RStudio to detect the new version automatically, close and reopen RStudio.Lemuelah
@Lemuelah Really I don't understand your comment, for me close and reopen RStudio ~~restart RStudioAsbestosis
@Asbestosis I recommend that you add to your answer that you must close and reopen RStudio (or restart RStudio, whichever wording you prefer). The "Then you change the path in your Rstudio option :Tools -> options -> General" did not work for me. However, restarting R did, so it would be good to update your answer to include this info.Lemuelah
Guys of course you need to restart Rstudio to take effectTalky
I use RStudio on Windows 10. I have the latest version of R (3.4.0 that I installed) and an earlier version (3.3.2 that was installed as a part of another program). RStudio doesn't load the latest version, i.e. 3.4.0, but I can manually set it on the latest version, and everything seems to be fine.Airway
If you download the deb file to your user Downloads file, then Rstudio will NOT find it. You will still need to <somehow> tell Rstudio where to find it.Jointed
maybe it's worth pointing out that on linux, you can update R via apt, just like everything else. perhaps you need to add the cran repository to your sources.list before you can get the newest release. for more info see here: cran.r-project.org/bin/linuxTjirebon
D
304

For completeness, the answer is: you can't do that from within RStudio. @agstudy has it right - you need to install the newer version of R, then restart RStudio and it will automagically use the new version, as @Brandon noted.

It would be great if there was an update.R() function, analogous to the install.packages() function or the update.packages(function).

So, in order to install R,

  1. go to http://www.r-project.org,
  2. click on 'CRAN',
  3. then choose the CRAN site that you like. I like Kansas: http://rweb.quant.ku.edu/cran/.
  4. click on 'Download R for XXX' [where XXX is your operating system]
  5. follow the installation procedure for your operating system
  6. restart RStudio
  7. rejoice

--wait - what about my beloved packages??--

ok, I use a Mac, so I can only provide accurate details for the Mac - perhaps someone else can provide the accurate paths for windows/linux; I believe the process will be the same.

To ensure that your packages work with your shiny new version of R, you need to:

  1. move the packages from the old R installation into the new version; on Mac OSX, this means moving all folders from here:

    /Library/Frameworks/R.framework/Versions/2.15/Resources/library
    

    to here:

    /Library/Frameworks/R.framework/Versions/3.0/Resources/library
    

    [where you'll replace "2.15" and "3.0" with whatever versions you're upgrading from and to. And only copy whatever packages aren't already in the destination directory. i.e. don't overwrite your new 'base' package with your old one - if you did, don't worry, we'll fix it in the next step anyway. If those paths don't work for you, try using installed.packages() to find the proper pathnames.]

  2. now you can update your packages by typing update.packages() in your RStudio console, and answering 'y' to all of the prompts.

    > update.packages(checkBuilt=TRUE)
    class :
     Version 7.3-7 installed in /Library/Frameworks/R.framework/Versions/3.0/Resources/library 
     Version 7.3-8 available at http://cran.rstudio.com
    Update (y/N/c)?  y
    ---etc---
    
  3. finally, to reassure yourself that you have done everything, type these two commands in the RStudio console to see what you have got:

    > version
    > packageStatus()
    
Daw answered 12/7, 2013 at 23:15 Comment(8)
Whenever somebody says you can't do something with R it just makes me want to do it. Looks like it's time to hack together something with RCurl and some system calls...Puttergill
I can't wait for you to make that happen :)Daw
It's not my own work but this has already been done for Windows users: github.com/talgalili/installrPuttergill
So the later answers has shown that neither the "correct" answer nor the highest voted answer gives a very complete answer, seems like this is so obvious here that something should be done to update this.Deodorant
I note for others that your personal library of R packages on OSX might alternatively be located under ~/Library/R instead of /Library/Frameworks/...Siloam
On Windows there is a personal library at C:\Users\username\R\win-library\3.2 (for R version 3.2.x) and the system libraries are at C:\Program Files\R\R-3.2.1\library (this is Windows Vista).Zoom
The newer versions of R, I upgraded from 3.2.3 to 3.3.0. Automatically, takes care of copying the packages from previous version and updates them. So, I guess no more issue of how to save packages.Burnedout
It seems there's finally an R package that updates R from RStudio using a Mac computer: github.com/AndreaCirilloAC/updateRCommunism
A
154

You install a new version of R from the official website.

RStudio should automatically start with the new version when you relaunch it.

In case you need to do it manually, in RStudio, go to :Tools -> options -> General.

Check @micstr's answer for a more detailed walkthrough.

Asbestosis answered 1/12, 2012 at 5:43 Comment(9)
RStudio detects this automatically... You only need to update the option if you want to use a different (previous, x32, x64) bit version.Wentletrap
@Brandon Bertelsen How? It never updates my R version. And the 'update' in the help menu is the update of RStudio only.Lorislorita
Outdated answer. You must restart RStudio after installing a new version of R. For RStudio to detect the new version automatically, close and reopen RStudio.Lemuelah
@Lemuelah Really I don't understand your comment, for me close and reopen RStudio ~~restart RStudioAsbestosis
@Asbestosis I recommend that you add to your answer that you must close and reopen RStudio (or restart RStudio, whichever wording you prefer). The "Then you change the path in your Rstudio option :Tools -> options -> General" did not work for me. However, restarting R did, so it would be good to update your answer to include this info.Lemuelah
Guys of course you need to restart Rstudio to take effectTalky
I use RStudio on Windows 10. I have the latest version of R (3.4.0 that I installed) and an earlier version (3.3.2 that was installed as a part of another program). RStudio doesn't load the latest version, i.e. 3.4.0, but I can manually set it on the latest version, and everything seems to be fine.Airway
If you download the deb file to your user Downloads file, then Rstudio will NOT find it. You will still need to <somehow> tell Rstudio where to find it.Jointed
maybe it's worth pointing out that on linux, you can update R via apt, just like everything else. perhaps you need to add the cran repository to your sources.list before you can get the newest release. for more info see here: cran.r-project.org/bin/linuxTjirebon
M
122

If you are using windows, you can use installr. Example usage here

Melly answered 1/12, 2013 at 15:17 Comment(6)
Just to note that you can run the update process from inside RStudioAnorexia
This is also my mode of choice. The code for moving all your packages is especially easy. # 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.Shoon
@Anorexia No. At least I have to use installr without Rstudio.Lorislorita
@Zhubarb , @kungfujam , @Shoon : How long does it take after running updateR() ? My Rstudio session seems to get hung up when I run this. Not sure if that's normal. Thanks!Agneta
I get an error: Error in file(con, "r") : cannot open the connection.. Any ideas?Dallon
@SoilSciGuy if you get "Error in file(con, "r")" try setInternet2(TRUE) see Troubleshooting sectionOrthopedist
J
73

I would recommend using the Windows package installr to accomplish this. Not only will the package update your R version, but it will also copy and update all of your packages. There is a blog on the subject here. Simply run the following commands in R Studio and follow the prompts:

# 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.
Jorum answered 14/3, 2015 at 14:36 Comment(3)
The installr package seems like a great solution but unfortunately is only for Windows.Gloze
@clemlaflemme : How long does it take after running updateR() ? My Rstudio session seems to get hung up when I run this. Not sure if that's normal. Thanks!Agneta
very reasonnable ; as for now I can't even remember, meaning it was not an issue.Hellenize
C
47

If you're using a Mac computer, you can use the new updateR package to update the R version from RStudio: http://www.andreacirillo.com/2018/02/10/updater-package-update-r-version-with-a-function-on-mac-osx/

In summary, you need to perform this:

To update your R version from within Rstudio using updateR you just have to run these five lines of code:

install.packages('devtools') #assuming it is not already installed
library(devtools)
install_github('andreacirilloac/updateR')
library(updateR)
updateR(admin_password = 'Admin user password')

at the end of installation process a message is going to confirm you the happy end:

everything went smoothly
open a Terminal session and run 'R' to assert that latest version was installed
Communism answered 27/7, 2016 at 17:7 Comment(8)
After installing successfully the new version of R (with the message above) the system wants to update packages and asks me if I want to restart R. In both cases (either yes or no) I got the following message install.packages(as.vector(needed_packages)) Error in install.packages : object 'needed_packages' not foundPray
@Pray this should have been fixed in later releases. please check out official repo for further updates: github.com/AndreaCirilloAC/updateRPiccadilly
@andrea-cirillo Yes, thanks. Problem does not appear anymore.Pray
This seems to be an issue again. Tried to update from 3.5.2 -> 3.6.2, and got the same message.Into
I also got the error message... However, I suspect the updateR worked, even though I got the error message, as when I restarted R it had updated to 3.6.2 and it looked like most of my packages survived the update as well.Citronella
May 2021 - UpdateR worked, but didn't make any changes to my packages. I used R.app console, not Rstudio.Machinery
For 4.1.3 --> 4.2.0, I had to load the stringr library in order to move the packages using updateR. This was because updateR internally uses the stringr function str_replace: github.com/AndreaCirilloAC/updateR/blob/master/R/…Illyricum
Also very important to note: updateR installs the Intel version of R, not the Arms version (for M1+ version). If you are using the Arms version, I strongly advise against using updateR.Illyricum
R
16

Paste this into the console and run the commands:

## How to update R in RStudio using installr package (for Windows)
## paste this into the console and run the commands
## "The updateR() command performs the following: finding the latest R version, downloading it, running the installer, deleting the installation file, copy and updating old packages to the new R installation."
## more info here: https://cran.r-project.org/web/packages/installr/index.html

install.packages("installr")
library(installr)
updateR()

## Watch for small pop up windows. There will be many questions and they don't always pop to the front. 
## Note: It warns that it might work better in Rgui but I did it in Rstudio and it worked just fine. 
Ravenravening answered 17/10, 2016 at 22:38 Comment(2)
It says " package ‘installr’ is not available (for R version 3.2.0)"...Nikolai
FYI, this still works. Whenever I need to update R, I search for my answer here and paste in the code. :)Ravenravening
T
8

There's a new package called installr that can update your R version within R on the Windows platform. The package was built under version 3.2.3

From R Studio, click on Tools and select Install Packages... then type the name "installr" and click install. Alternatively, you may type install.packages("installr") in the Console.

Once R studio is done installing the package, load it by typing require(installr) in the Console.

To start the updating process for your R installation, type updateR(). This function will check for newer versions of R and if available, it will guide you through the decisions you need to make. If your R installation is up-to-date, it will return FALSE.

If you choose to download and install a newer version. There's an option for copying/moving all of your packages from the current R installation to the newer R installation which is very handy.

Quit and restart R Studio once the update process is over. R Studio will load the newer R version.

Follow this link if you wish to learn more on how to use the installr package.

Tychon answered 21/1, 2016 at 6:21 Comment(0)
T
4

Just restart R Studio after installing the new version of R. To confirm you're on the new version, >version and you should see the new details.

Tolerance answered 18/4, 2013 at 16:21 Comment(0)
C
4

Don't use Rstudio to update R. Rstudio IS NOT R, Rstudio is just an IDE. This answer is a summary of previous answers for different OS. For all OS it is convenient to have a look in advance what will happen with the packages you have already installed here.

WINDOWS ->> Open CMD/Powershell as an administrator and type "R" to go into interactive mode. If this does not work, search and run RGui.exe instead of writing R in the console ...and then:

lib_path <- gsub( "/", "\\\\" , Sys.getenv("R_LIBS_USER"))
install.packages("installr", lib = lib_path)
install.packages("stringr", lib_path)
library(stringr, lib.loc = lib_path)
library(installr, lib.loc = lib_path)
installr::updateR()

MacOS ->> You can use updateR package. The package is not on CRAN, so you’ll need to run the following code in Rgui:

install.packages("devtools")
devtools::install_github("AndreaCirilloAC/updateR")
updateR(admin_password = "PASSWORD") # Where "PASSWORD" stands for your system password

Note that it is planned to merge updateR and installR in the near future to work for both Mac and Windows.

Linux ->> For the moment installr is NOT available for Linux/MacOS (see documentation for current version 0.20). As R is installed, you can follow these instructions (in Ubuntu, although the idea is the same in other distros: add the source, update and upgrade and install.)

Cusco answered 10/11, 2017 at 19:44 Comment(1)
Is there also a way to tell updateR the administrator username?Brushwork
P
1

I found that for me the best permanent solution to stay up-to-date under Linux was to install the R-patched project. This will keep your R installation up-to-date, and you needn't even move your packages between installations (which is described in RyanStochastic's answer).

For openSUSE, see the instructions here.

Py answered 15/10, 2014 at 16:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.