Updating R and RStudio and avoiding dependency hell of updating to new major version (2024)

[This article was first published on Rblog | Claudiu's Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Updating R (for Windows)

The most straightforward way to update R on Windows is to use the installr package. installr can also be used to install also ‘Rtools’, ‘RStudio’ and ‘Git’.

Keep in mind that it is not recommended to use installr from RStudio, so use R instead. Some more details on updating R with installr can be found here.

## Update R for Windows - best from R, do not use RStudio# Load or, if necessary, install & load {installr} packageif(!require(installr)) {install.packages("installr");require(installr)}

After installing/loading installr you should chose your preferred method for updating: non-interactive or interactive.

For non-interactive full update sequence use:

To non-interactively install, move packages from old version to new version, update packages and quit R run this:

# For non-interactive full update sequence use:installr::updateR(browse_news = F,install_R = T,copy_packages = T,copy_site_files = F,keep_old_packages = F,update_packages = T,start_new_R = F,quit_R = T) # install, move, update.package, quit R.

For interactive pop-up guided full update sequence use:

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

# For interactive pop-up guided full update sequence use:installr::updateR()
Sequential steps by component functions

You can also run each step of the sequence by calling the component functions of the installr::updateR() function:

installr::check.for.updates.R() # tells you if there is a new version of R or not.installr::install.R() # download and run the latest R installerinstallr::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)

Update RStudio

For interactive install from inside RStudio

  1. Open RStudio.

  2. Navigate to Help Menu.

  3. Check for updates.

  4. If any new update is available, click on Install.

For non-interactive install from R

We can use installr package to install the new RStudio.

# Install RStudioinstallr::install.RStudio()

Updating Packages

If you followed the steps above, you would have moved (i.e. cut/paste) the packages from older version to new version by using installr. Now, if you transition beween minor version of R, you just need to update the packages:

# Update packagesupdate.packages(ask = FALSE) # update all packages except those installed from other sources (e.g. with devtools::install_github())

Unfortunately, if you are updating between major version (e.g. R version 3.0 to R version 4.0) updating won’t help because you will get the infamous error:

Package ‘XXX’ was installed before R 4.0.0: please re-install it

This means that you need to re-install all of your packages, which may take some time. I will share the sequence I use, but keep in mind that it uses install.packages() and is sub-optimal because some packages that are frequent dependencies of others get installed more than once (a single version will remain though).

  1. You should know where your packages live
# Paths to installed packages.libPaths()
  1. Detach all non-core packages

You can detach packages from console or RStudio, but the easiest and safest way is to use pacman.

# Restart R.rs.restartR()# Clear workspacerm(list = ls(all = TRUE))# Detach all packages# Load or, if necessary, install & load {pacman} packageif(!require(pacman)) {install.packages("pacman");require(pacman)}pacman::p_unload(pacman::p_loaded(), character.only = TRUE)

If needed there is a package called nothing that when loaded will unload all of the loaded packages. You can install it from GitHub and use it like this:

devtools::install_github("romainfrancois/nothing")require(nothing, quietly = TRUE)loadedNamespaces() # only package {base} should remain
  1. Check what packages remain loaded

If you followed along, only core packages should remain loaded.

# Check what packages remain loadedloadedNamespaces()
  1. Re-install all previously installed packages

This will take a while …

# Re-install packagesto_install <- unname(installed.packages()[, "Package"])for(lib in to_install) install.packages(lib, dependencies = TRUE)

Related

To leave a comment for the author, please follow the link and comment on their blog: Rblog | Claudiu's Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Updating R and RStudio and avoiding dependency hell of updating to new major version (2024)

FAQs

What is the best way to update R and RStudio? ›

If you want to update R and RStudio:

One way is to run the actual R program. There, you can go to the “R” menu and click “Check for R Updates” (see image below). If you do that, R will tell you the current version you're on, and whether or not there is a more updated version that you can download (circled in blue).

How do I update R to a specific version in RStudio? ›

Switching R versions in Windows
  1. In RStudio, goto "Tools" then "Global Options"
  2. Click "Change" next to the "R version" drop down menu and a window will pop out, allowing you to change the R version.
  3. For Mac users, download rswitch to change R version used https://rud.is/rswitch/.

Can you update R without losing packages? ›

The key thing to be aware of is that when you update R, if you just download the latest version from the website, you will lose all your packages. The easiest way to update R and not cause yourself a huge headache is to use the installr package.

Should I update my R version? ›

While there is no requirement to regularly update your installation of R and RStudio, occasionally updating your software ensures that you have all of latest functionality and resources. The R Project Team and the Foundation for Open Access Statistics [developers of RStudio] regularly update these applications.

Should I install R or RStudio first? ›

We need to install two things onto your computer. The first is R, this is the programming language we will use. After that we need to install RStudio, this is a front end program that lets you write R code, view plots, and do many other useful things.

Which version of R is best? ›

We want a recent, stable and non-bugged version. So the best choice is: The last patch of the penultimate minor version. As we are currently in 4.3. 0, this would be version 4.2.

How do I change the version of R in RStudio server? ›

You can select different versions of R by selecting it from the drop down list at the top of the browser window. The drop down menu will allow you to select the version of R you want to use.

What version of R is RStudio using? ›

The RStudio IDE requires R version 3.0. 1 or higher. Since R versions can be installed side-by-side on a system, RStudio needs to select which version of R to run against. The way this occurs varies between platforms—this article covers how version selection is handled on each platform.

How long does it take to update R? ›

Upgrading R on Windows and Mac

If you only see the option to upgrade to an older version of R, then change your mirror or try again in a few hours (it usually take around 24 hours for all CRAN mirrors to get the latest version of R).

How often should you update R packages? ›

Best Practices for Updating
  • Update packages frequently (weekly)
  • Update R quarterly (or at least check)
  • For complete reproducibility for a project check out the {renv} package.
  • Don't copy packages over between R versions–start clean and fresh.

Do I need to uninstall R before installing new version? ›

To Upgrade your R Environment

Uninstall the old version of R. Uninstalling R removes files from the initial installation, but not packages that have been installed or updated. See the third-party R documentation for steps to uninstall R for your machine configuration. Install the new version of R from CRAN.

Can I use R without downloading? ›

RStudio Cloud is an application that runs in your web browser. It allows you to write and access R code wherever you go. It even works on your tablet because it does not require installation. However, do expect it to run slower if your internet connection is not fast or stable.

Why is it needed for RStudio to update regularly? ›

14. Why is it needed for R studio to update regularly? Explanation: RStudio is very popular with a nice interface and well thought out, especially for more advanced usage. It can be a bit buggy, so make sure you update it regularly.

How do I update R and RStudio? ›

From within RStudio, go to Help… Check for Updates to install newer version of RStudio (if available, optional). To update packages, go to Tools… Check for Package Updates.

What is the recommended version of R? ›

0, this would be version 4.2. 3. That's the recommended one for a production system at the moment. And as soon as the R team releases the next minor version – 4.4.

What is the best software for R? ›

7 Best IDEs For R Programming [2024]
  • RStudio.
  • Jupyter Notebook.
  • Visual Studio Code.
  • R Tools for Visual Studio.
  • Emacs & ESS.
  • Eclipse with StatET.
  • Sublime Text.
May 26, 2024

What version of R does RStudio use? ›

The RStudio IDE requires R version 3.0. 1 or higher. Since R versions can be installed side-by-side on a system, RStudio needs to select which version of R to run against. The way this occurs varies between platforms—this article covers how version selection is handled on each platform.

What is the difference between R software and RStudio? ›

R is an open-source programming language that is used for programming, data analysis and data visualisation. It is widely used for statistical analysis. RStudio is a Graphical User Interface (GUI) for R. R and RStudio are available on all of the University-managed computers across campus and via UniDesk.

Top Articles
Latest Posts
Article information

Author: Domingo Moore

Last Updated:

Views: 6254

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Domingo Moore

Birthday: 1997-05-20

Address: 6485 Kohler Route, Antonioton, VT 77375-0299

Phone: +3213869077934

Job: Sales Analyst

Hobby: Kayaking, Roller skating, Cabaret, Rugby, Homebrewing, Creative writing, amateur radio

Introduction: My name is Domingo Moore, I am a attractive, gorgeous, funny, jolly, spotless, nice, fantastic person who loves writing and wants to share my knowledge and understanding with you.