4  Installing R under macOS

[The rest of this paragraph is only relevant after release.] The front page of a CRAN site has a link ‘Download R for (Mac) OS X’ which takes you to a new page. Two files are offered for download, R-4.4.0 Under development-arm64.pkg and R-4.4.0 Under development.pkg. Both are for macOS 11 or later (Big Sur, Monterey, Ventura, Sonoma, …).

The first is for ‘Apple Silicon’ (aka ‘M1’, ‘M2’ or ‘M3’) Macs, the second for older Macs with an x86_64 (Intel) CPU.

Package R-4.4.0 Under development.pkg also be installed on ‘Apple Silicon’ CPUs using ‘Rosetta’ emulation1, but the native build is preferred. It is a little faster (and for some tasks, considerably so) but may give different numerical results from the more common x86_64 platforms (on Windows, Linux, … as well as macOS) as ARM hardware lacks extended-precision floating-point operations.

1 You may be asked to install Rosetta at first use – https://support.apple.com/en-us/102527 – which may need administrator privileges.

It is important that if you use a binary installer package that your OS is fully updated: look at ‘Software Update’ in ‘System Preferences’ to be sure.

To install, just double-click on the icon of the file you downloaded. At the ‘Installation Type’ stage, note the option to ‘Customize’. This currently shows four components: everyone will need the ‘R Framework’ component: the remaining components are optional. (The ‘Tcl/Tk’ component is needed to use package tcltk. The ‘Texinfo’ component is only needed by those installing source packages or R from its sources.)

Note for Ventura users: installation from the Downloads folder may not be allowed or may require additional authorization, so we suggest you download somewhere else such as your desktop or home folder.

These are Apple Installer packages. If you encounter any problem during the installation, please check the Installer log by clicking on the “Window” menu and item “Installer Log”. The full output (select “Show All Log”) is useful for tracking down problems. Note that the installer is clever enough to try to upgrade the last-installed version of the application where you installed it (which may not be where you want this time …).

Various parts of the build require XQuartz to be installed: see https://www.xquartz.org/releases/.2 These include the tcltk package and the X11 graphics device: attempting to use these without XQuartz will remind you. This is also needed for some builds of the cairographics-based devices (which are not often used on macOS) such as png(type = "cairo") and svg() and some third-party packages (e.g. rgl).

2 At the time of writing, version 2.8.5 or later.

If you update your macOS version, you should re-install R (and perhaps XQuartz): the installer may tailor the installation to the current version of the OS.

Installers for R-patched and R-devel are usually available from https://mac.R-project.org. (Some of these packages may be unsigned/not notarized: to install those Control/right/two-finger click, select Open With and Installer.)

For building R from source, see macOS.

4.1 Running R under macOS

There are two ways to run R on macOS from a CRAN binary distribution.

There is a GUI console normally installed with the R icon in /Applications which you can run by double-clicking (e.g. from Launchpad or Finder). (If you cannot find it there it was possibly installed elsewhere so try searching for it in Spotlight.) This is usually referred to as R.APP to distinguish it from command-line R: its user manual is currently part of the macOS FAQ at https://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html and can be viewed from R.APP‘s ’Help’ menu.

You can run command-line R and Rscript from a Terminal3 so these can be typed as commands as on any other Unix-alike: see the next chapter of this manual. There are some small differences which may surprise users of R on other platforms, notably the default location of the personal library directory (under ~/Library/R, e.g. ~/Library/R/x86_64/4.2/library), and that warnings, messages and other output to stderr are highlighted in bold.

3 The installer puts links to R and Rscript in /usr/local/bin. If these are missing or that is not on your path, you can run directly the copies in /Library/Frameworks/R.framework/Resources/bin or link those yourself to somewhere on your path.

Those using the zsh shell (the default for new user accounts as from Catalina) might find the command R being masked by the zsh builtin r (which recalls commands). One can use a full path to R in an alias, or add disable r to ~/.zshrc.

If you have installed both installer packages on an arm64 Mac, the last installed will be used.

It has been reported that running R.APP may fail if no preferences are stored, so if it fails when launched for the very first time, try it again (the first attempt will store some preferences).

Users of R.APP need to be aware of the ‘App Nap’ feature (https://developer.apple.com/library/archive/releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10_9.html) which can cause R tasks to appear to run very slowly when not producing output in the console. Here are ways to avoid it:

Using the X11 graphics device or the X11-based versions of View() and edit() for data frames and matrices (the latter are the default for command-line R but not R.APP) requires XQuartz to be installed.

Under some rather nebulous circumstances messages have been seen from fontconfig about missing/unreadable configuration files when using cairo-based devices, especially X11(type = "cairo"). With XQuartz installed there are two fontconfig areas from different versions and it can help to set

setenv FONTCONFIG_PATH /opt/X11/lib/X11/fontconfig

Another symptom has been that italic/oblique fonts are replaced by upright ones.

4.2 Uninstalling under macOS

R for macOS consists of two parts: the GUI (R.APP) and the R framework. Un-installation is as simple as removing those folders (e.g. by dragging them onto the Bin aka Trash). The typical installation will install the GUI into the /Applications/R.app folder and the R framework into the /Library/Frameworks/R.framework folder. The links to R and Rscript in /usr/local/bin should also be removed.

If you want to get rid of R more completely using a Terminal, simply run:

sudo rm -Rf /Library/Frameworks/R.framework /Applications/R.app \
   /usr/local/bin/R /usr/local/bin/Rscript

The installation consists of up to four Apple packages:4 for the Intel build, org.R-project.x86_64.R.fw.pkg, org.R-project.x86_64.R.GUI.pkg, org.r-project.x86_64.tcltk and org.r-project.x86_64.texinfo. You can use sudo pkgutil --forget if you want the Apple Installer to forget about the package without deleting its files (useful for the R framework when installing multiple R versions in parallel), or after you have deleted the files. NB: the package names are case-sensitive and the R domain is named inconsistently.

4 At the time of writing: use pkgutil --pkgs | grep -i org.r-project to check.

Uninstalling the Tcl/Tk and Texinfo components (which are installed under /opt/R/x86_64 on a x86_64 build and /opt/R/arm64 for an arm64 one) is not as simple. You can list the files they installed in a Terminal by e.g.

pkgutil --files org.r-project.x86_64.tcltk
pkgutil --files org.r-project.x86_64.texinfo

(For the ‘Apple Silicon’ build, replace x86_64 by arm64.) These are paths relative to /, the root of the file system.

If you are not compiling R nor installing packages from source you could remove all of /opt/R/x86_64 or /opt/R/arm64.

4.3 Multiple versions

The installer will remove any previous version5 of the R framework which it finds installed. This can be avoided by using pkgutil --forget (see the previous section). However, note that different versions are installed under /Library/Frameworks/R.framework/Versions as 4.4 (or 4.4-arm64), 4.3 and so on, so it is not possible to have different 4.x.y versions installed for the same x and CPU type.

5 More precisely, of the Apple package of the same name: this means that Intel and ARM versions can be installed together.

R.APP will always run the ‘current’ version, that is the last installed version.

Footnotes