Because R and R Studio don’t necessarily warn you when they need upgrading, I had to figure it out myself when I started getting some weird bugs running assignments during an R class. Alas, I needed to update R to the latest version, and in the process decided to update RStudio as well. Here is how I went about it.
Video created by Johns Hopkins University for the course 'R Programming'. This week covers the basics to get you started up with R. The Background Materials lesson contains information about course mechanics and some videos on installing R.
t’s important to first check the R version. You can either just look at the top comment when you load R Console or R Studio:
You can also run the following command in the R console or in RStudio which will give you a lot more information:
R.Version()
The two main things you’re looking for when you run R.Version() are:
major – the major version number
and
minor – the minor version number, including the patch level
Of course to check what your R Studio version is you just need to click on the Help menu item and then click on “About RStudio”.
To update R, go to CRAN and download the latest version and run the install. When you restart RStudio or R Console it should automagically detect and use the new R version. You can manually change what version of R your RStudio is using at any time. See the note at the end of this post.
To update RStudio, go to the RStudio website and download the latest version for Mac. Once it’s downloaded, drag it into Applications folder (that’s how it is at the time of this posting) and allow it to replace your existing RStudio version.
That’s pretty much all you need to do. To be double sure you can click on Help -> Check for Updates to make sure you’re on the latest version of RStudio.
NOTE: When you update R, the older versions are not deleted, so you can have different versions of R installed side by side on your system. To see what versions of R are installed on your Mac, open terminal and run the following command:
ls -l /Library/Frameworks/R.framework/Versions/
The output of this command should be a list of the R versions on your system, assuming you install R to the default location. Mine looks something like this:
To change which version of R RStudio uses you can use the RSwitch utility (found here). I haven’t tried this yet so can’t speak to how or whether it works. I prefer to use the symlink method using the ln -s command. For example the following command will make RStudio use the version of 3.3 that’s on my Mac. You can switch 3.3 out with whatever version you want as long as it’s listed as being installed on your Mac when you run the ln -l command I gave above.
ln -sfhv /Library/Frameworks/R.framework/Versions/3.3 /Library/Frameworks/R.framework/Versions/Current
Fair warning: This ln -s command seems to break R Console, but R Studio continues to work fine, and that’s what I use most times anyway. I’m not entirely sure how to do this for R console, but if I do find out I will update this post.
Hope this is helpful for someone.
R Studio For Machine Learning
When was the last time you update your R and RStudio?
I installed RStudio and R a year ago, and never update it since then. Today I just noticed I cannot install new R packages because of my old R version. So I explore some ways to update R and would like to share with someone who is also looking to update R on RStudio.
The problem
RStudio and R cannot update on their own because some packages may not work after switching to the new version (You can still downgrade R version in RStudio if something went wrong though). After you install the new version, the previously installed packages will not go to next version. So it is required extra procedures to move the packages.
Here are 3 ways you can update R version in RStudio. Note that we need to move the install R packages, which I will show how at the end.
3 Solutions to update R on RStudio
Solution 1) Manually install (Recommended if you don't care about the old packages)
The first method is to download a new version of R from R website > CRAN. Then restart your RStudio. The new R version will be loaded automatically.
The new R version appear right after I install R and restart RStudio
Update 29/05/2019: For Mac users, solution 3 is too painful and not working well for me. This method is fast and working well. I would recommend to save your time from headache and use this method. Take note of your previous packages so you can install them again as needed.
Solution 2) Windows only – use installr
installr is the R package which helps install and update software.
The R code you will need for updating R is: (credit goes to Cara Wogsland for the code)
install.packages('installr')
library(installr)
updateR()
You can find the tutorial on how to use installr to update RStudio on R-Statistics website.
Solution 3) Mac only – use updateR
Similar to installr, updateR is the package to help updating R on Mac OS.
Installing R And R Studio
The R code you will need is these 5 lines: (credit goes to jroberayalas for the code)
install.packages('devtools') #assuming it is not already installed
library(devtools)
install_github('andreacirilloac/updateR')
library(updateR)
updateR(admin_password = 'Admin user password')
You can find in-depth tutorial on how to use updateR package on this blog.
How to move the previously installed R packages
This is the instructions for Mac OS user (who used solution 1 or 3 above). For Windows user, installr package will do this for you
(credit goes to RyanStochastic and micstr):
1. Move all folders from your old R version to new R version.
/Library/Frameworks/R.framework/Versions/x.xx/Resources/library
Replace x.xx with the old and new R version at a time.
Note that you have to move only the packages that are not currently in the destination folder (because those are the base packages, and you don’t want to ruin them). But if you already did replaced everything, the next step will solve this for you.
If you cannot find the proper path, you can run this command to check: installed.packages()
2. Update the moved packages
Run the following command in R. Type ‘y’ for every question that popped up.
update.packages(checkBuilt=TRUE)
3. Type the following command in R to check if everything went well
version
packageStatus()
That’s it! Hope you guys success in updating R. If not, please check in the reference link below.
References: https://stackoverflow.com/questions/13656699/update-r-using-rstudio