Changing R versions for the RStudio Desktop IDE

Follow

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.

Windows

On Windows, the RStudio IDE uses the system's current version of R by default. When R is installed on Windows it writes the version being installed to the Registry as the "current" version of R (the specific registry keys written are described here). This is the version of R which RStudio runs against by default.

You can override which version of R is used via General panel of the RStudio Options dialog. This dialog allows you to specify that RStudio should always bind to the default 32 or 64-bit version of R, or to specify a different version altogether:

Note that by holding down the Control key during the launch of RStudio you can cause the R version selection dialog to display at startup.

Mac OS X

R from CRAN

On Mac OS X, if the only version of R you have installed is the standard R distribution from CRAN, then by default the RStudio IDE will run against the current version of R.Framework. You can list all of the versions of R.Framework on your system and determine which one is considered the current one by executing the following command:

ls -l /Library/Frameworks/R.framework/Versions/

To change the current version of R.Framework, you can either:

  • Run the installer from CRAN for the R version you want to be current
  • Use the RSwitch utility available at: https://rud.is/rswitch/
  • Update the R.framework/Versions/Current directory alias directly using ln -s

R from source (including MacPorts and Homebrew)

When R is installed from CRAN on OS X, the R executable is installed at /usr/bin/R. However, if R is installed directly from source or via a package manager like MacPorts or Homebrew, then the R executable is installed to either /usr/local/bin/R (Homebrew) or /opt/local/bin/R (MacPorts). In order to support these variations, RStudio scans for the R executable in the following sequence:

  1. /usr/bin/R
  2. /usr/local/bin/R
  3. /opt/local/bin/R

If the RStudio IDE is not able to locate R by scanning these locations, it will fall back to using whatever version of R is located at /Library/Frameworks/R.framework/.

If you want to override the version of R selected by RStudio's default behavior then you can set the RSTUDIO_WHICH_R environment variable to the R executable that you want to run against. For example, to force RStudio to use the R executable located at /usr/local/bin:

export RSTUDIO_WHICH_R=/usr/local/bin/R

Note that in order for RStudio to see this environment variable it needs to be launched from a terminal where the variable has been set to the desired value and exported.

Linux Desktop

On Linux, RStudio Desktop IDE, RStudio Server Open Source, and RStudio Workbench (previously RStudio Server Pro) all use the version of R pointed to by the output of the following command:

which R

The which command performs a search for the R executable using the system PATH. RStudio will therefore by default bind to the same version that is run when R is executed from a terminal.

For versions of R installed by system package managers (e.g. r-base on Debian or Ubuntu) this will be /usr/bin/R. For versions of R installed from source this will typically (but not always) be /usr/local/bin/R.

If RStudio is unable to locate R using which R, it will fall back to scanning explicitly for the R script in the /usr/local/bin and /usr/bin directories.

If you want to override which version of R is used then you can set the RSTUDIO_WHICH_R environment variable to the R executable that you want to run against. For example:

export RSTUDIO_WHICH_R=/usr/local/bin/R

Not that in order for RStudio to see this environment variable when launched from the Ubuntu desktop Applications menu (as opposed to from a terminal) it must be defined in the ~/.profile file.

Need Help?

RStudio Workbench / RStudio Server Pro customers may open a discussion with RStudio Support at any time by following these instructions.

You may also ask for help from R and RStudio users on community.rstudio.com. Be sure to include a reproducible example of your issue. Click here to start a new community discussion.

Comments