4 Installing R under macOS ¶
Next: Running R, Previous: Installing R under Windows, Up: R Installation and Administration [Contents][Index]
[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.5.0 Under development-arm64.pkg and R-4.5.0 Under development-x86_64.pkg. Both are for macOS 11 or later (Big Sur, Monterey, Ventura, Sonoma, …).
The first is for ‘Apple Silicon’ (aka ‘M1’, ‘M2’, …) Macs, the second for older Macs with an x86_64’ (Intel) CPU.
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/.20 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).
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 Terminal21 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/arm64/4.4/library), and that warnings, messages and other output to stderr are highlighted in bold.
Those using the zsh
shell (the default for new user accounts) 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.
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:
Ensure that the console is completely visible (or at least the activity indicator at the top right corner is visible).
In a Terminal, run
-project.R NSAppSleepDisabled -bool YES defaults write org.R
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
/opt/X11/lib/X11/fontconfig setenv FONTCONFIG_PATH
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 Bin22). 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:23 for the ‘Apple Silicon’ build, org.R-project.arm64.R.fw.pkg
, org.R-project.arm64.R.GUI.pkg
, org.r-project.arm64.tcltk
and org.r-project.arm64.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.
Uninstalling the Tcl/Tk and Texinfo components (which are installed under /opt/R/arm64 on a arm64’ build and /opt/R/x86_64 for an x86_64’ one) is not as simple. You can list the files they installed in a Terminal by e.g.
--files org.r-project.arm64.tcltk
pkgutil --files org.r-project.arm64.texinfo pkgutil
(For the ’Intel build, replace arm64
by x86_64
.) 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/arm64 or /opt/R/x86_64.
4.3 Multiple versions ¶
The installer will remove any previous version24 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-arm64 (or 4.4-x86_64), 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.
R.APP will always run the ‘current’ version of R, that is the last installed version.