Table of Contents
Motivation
Whether working or studying everybody uses various sorts and types of software on their computer. Students taking Statistical Courses, as taught by the Mathematical and Statistical Methods group at Wageningen University & Research, will most likely use R.
The instructions in this post will show how to (re-)install R on a desktop or laptop computer running macOS as operating system.
In the text some symbol combinations are used for shortcuts, the following table explains the meaning of these symbols in relation to specific keys on your keyboard. To use the shortcuts press the keyboard keys simultaneously, e.g. ⇧⌘A means ⇧+⌘+A.
Icon | Keyboard Meaning | Icon | Keyboard Meaning | |||
---|---|---|---|---|---|---|
⌘ | command | ⇪ | caps lock | |||
⌥ | option (or alt) | ↩ | carriage return (return/enter) | |||
⌃ | control | ⌫ | delete/backspace | |||
fn | function | ⌦ | forward delete (fn + ⌫) | |||
⇧ | shift (either left or right) | ⎋ | escape |
Completely removing R from macOS
If you have previously installed R and wish to re-install the latest version or your current installation is not working as you expect, you first need to delete everything related to R. In macOS a complete removal is somewhat complicated, but doable if you follow all steps precisely as provided in this post.
For the complete removal of everything related to R the Terminal application will be used. In your Finder > Applications (shortcut: ⇧⌘A) there is a Utilities folder as depicted in Figure 1 below.
Within this Utilities folder, which can be directly accessed by using the ⇧⌘U shortcut, the Terminal application is contained. The icon in Figure 2 shows what the Terminal application looks like in the Finder > Applications > Utilities folder.
The Terminal application can also be started via Lauchpad under the ‘Other’ group.
Steps for a complete removal of R on macOS:
- Start the Terminal application. The terminal console prompt, where the commands will be entered, is depicted by a
%
or a$
sign. Which sign is shown, depends whether your default shell is zsh (%
sign) or bash ($
sign). - To delete the R application copy (⌘C) the following line, paste (⌘V) it behind the terminal console prompt and press return (↩) to execute. Provide the macOS password when asked (the typed password will not be visble!).
sudo rm -r /Applications/R.app
- To delete the whole framework running behind R copy (⌘C) the following line, paste (⌘V) it behind the console prompt in the terminal and press return (↩) to execute. No password will be asked anymore, as long as you do not close the terminal application.
sudo rm -r /Library/Frameworks/R.framework
- To be able to re-install R the installation receipts need to be removed. This is done by copying (⌘C) the following lines (including the *) one by one, pasting (⌘V) them behind the prompt in the terminal and pressing return (↩) to execute.
sudo rm -r /private/var/db/receipts/org.r-project.*
sudo rm -r /private/var/db/receipts/org.R-project.*
- Delete R application support by copying (⌘C) the following line, pasting (⌘V) it behind the prompt in the terminal and pressing return (↩) to execute.
sudo rm -r ~/Library/Application Support/R
- Clean the cache of R by copying (⌘C) the following line, pasting (⌘V) it behind the prompt in the terminal and pressing return (↩) to execute.
sudo rm -r ~/Library/Caches/org.R-project.org
- To remove R preferences copy (⌘C) the following line, paste (⌘V) it behind the prompt in the terminal and press return (↩) to execute.
sudo rm ~/Library/Preferences/org.R-project.org.plist
- Deletion of all previously installed user packages is achieved by copying (⌘C) the following line, pasting (⌘V) it behind the prompt in the terminal and pressing return (↩) to execute. A notification will be given in case the folder does not exist.
sudo rm -r ~/Library/R
- Delete user created environment variables, used at startup of R, copy (⌘C) the following line, paste (⌘V) it behind the prompt in the terminal and press return (↩) to execute. A notification will be given in case the file does not exist.
sudo rm ~/.Renviron
- Finally delete the user folder with additional settings by copying (⌘C) the following line, pasting (⌘V) it behind the prompt in the terminal and pressing return (↩) to execute. A notification will be given in case the folder does not exist.
sudo rm -r ~/.R
Having performed all 10 steps given above, your mac will be ready for a new installation of R. Leave the terminal console open for now, you might need it later on.
Download
At the time this post was written, the latest release of R was version 3.6.3. It has been updated to the latest release version 4.4.1 of R (nicknamed: “Race for Your Life”) for macOS Big Sur or higher.
For newer versions of R than 3.6.3 the steps described below are the same and still correct, but start with a newer version of the downloaded package file of R. The screenshots in this post have not been updated. Therefore, what you see during your installation will differ with respect to the version number shown in the screenshots.
For macOS there are four downloads for R available on the R-project website. To see which version of macOS is installed on your mac, click on in the menu bar and select ‘About This Mac’.
NOTE: If you are using a mac with the newest M1, M2, or M3 processor, download the Apple Silicon arm64 build!
Download R for your specific version of macOS using one of the following links:
- For macOS El Capitan (10.11.x) up to and including macOS Mojave (10.14.x): R 3.6.3 (ca. 77 MB, regular 64-bit)
- For macOS High Sierra (10.13.x) up to and including macOS Catalina (10.15.x): R 4.2.3 (ca. 89 MB, regular 64-bit)
- For macOS Big Sur (11.x) and higher (Intel 64-bit build): R 4.4.1 (ca. 96 MB, notarized and signed Intel 64-bit build)
- For macOS Big Sur (11.x) and higher (Apple silicon arm64 build for M1, M2 or M3 processor MACS only): R 4.4.1 (ca. 94 MB, notarized and signed ARM 64-bit build)
macOS Ventura (13.x) users: there is a known bug in Ventura preventing installations from some locations without a prompt. If the installation fails, move the downloaded file away from the Downloads folder (e.g., to your home or Desktop)
Installation
For installing R on macOS follow these steps:
- Open the downloaded file, either R-3.6.3.nn.pkg, R-4.2.3.pkg, R-4.4.1-x86_64.pkg, or R-4.4.1-arm64.pkg depending or your version of macOS or processor (as explained above). This file will most likely reside in Finder > Downloads (shortcut: ⌥⌘L). The file can more easily be found by switching into List view (shortcut: ⌘2). To switch to Icon view use the shortcut: ⌘1. The installer package will resemble the image displayed below in Figure 3 (text underneath can, and probably will, differ!).
- The installler will start and display the introduction as shown below in Figure 4. Click the ‘Continue’ button to proceed.
- Now the Read Me for the software to be installed as displayed in Figure 5 below. Click the ‘Continue’ button to proceed.
- Right after the Read Me a Software Licence Agreement will appear. By clicking the ‘Continue’ button you will be asked to agree with this software licence agreement as diplayed below in Figure 6. Click on ‘Agree’ to proceed.
- The installer will select the best destination to install the software for you and will display the Installation Type as shown in Figure 7. Click on the ‘Install’ button to start the software installation.
Do not Customise the installation type, unless you know what you are doing.
- Before the software installation will commence, confirmation of the user is requested as displayed below in Figure 8. Either use the finger print scanner on the touch bar of your mac or confirm using the password of your mac.
- The software installer will start installing R onto your mac. When completed the installer will show a summary stating that the installation was successful as shown in Figure 9 below. Click on the ‘Close’ button.
- The installer will finally ask you whether you want to keep or move to R installer package to the trashbin. Click ‘Move to Bin’ to discard the installer package.
Congratulations 😆, you now have R 3.6.3 or higher installed on your mac! Before actively using the R application, some configuration will be required. The configuration is described in the next section.
Configure the R application on macOS
To configure the R application on macOS perform the following steps:
- Start the R application from Finder > Applications (shortcut: ⇧⌘A) or via Launchpad. The icon representing the R application is shown below in Figure 10.
- The R Console will open, as shown in Figure 11 below, and the cursor will be ready for input behind the prompt, indicated by the
>
sign. In case the R Console displays a non-UTF8 locale warning, than this needs to be remedied first. Go to the section entitled Fix R application non-UTF8 locale warning in this post to resolve this issue.
- Navigate the mouse pointer to the menu bar click on ‘R’ > ‘Preferences…’ (shortcut: ⌘,) to open the R application preferences. The Preferences window displayed in Figure 12 will appear.
- Click on Startup. The Preferences window will change into what is shown in Figure 13.
- Match the Startup settings displayed above in Figure 13. To select the Default CRAN mirror click on the ‘Select’ button. The window shown below in Figure 14 will appear. Select ‘0-Cloud [https]’ and click ‘OK’ to confirm. Having matched the settings, close the window using the red ball in the top left corner of the Startup window.
Quit the R application either by:
- Typing
q()
orquit()
behind the R Console prompt (indicated by the>
sign) and pressing return (↩) to execute. - Using the keyboard shortcut: ⌘Q
- Navigating the mouse pointer to the menu bar and clicking ‘R’ > ‘Quit R’
- Navigation the mouse pointer to the top left corner of the R Console window and clicking on the red ball
- Typing
No matter what you choose, you will always be asked whether you want to save a workspace image as shown below in Figure 15. Just click on the ‘Don’t Save’ button to end the R application.
Having configured the R application, you are now ready to actively start using it!
Fix R application non-UTF8 locale warning
When the R Console displays a non-UTF8 locale warning at the startup of the R application, it will look like the image shown below in Figure 16.
The remedy for this issue is not difficult, just perform the following steps:
- Go to the open terminal console. If you do not have one yet, open the Terminal application from Finder > Applications > Utilities (shorcut: ⇧⌘U) or via Lauchpad under the ‘Other’ group. The terminal console prompt, where the commands will be entered, is depicted by a
%
or a$
sign. Which sign is shown, depends whether your default shell is zsh (%
sign) or bash ($
sign). - Copy (⌘C) the following line, paste (⌘V) it behind the prompt in the terminal console and press return (↩) to execute the command.
defaults write org.R-project.R force.LANG en_US.UTF-8
- Quit the active terminal console by typing
exit
and pressing return (↩) to execute. To quit the Terminal application completely you can use the keyboard shortcut: ⌘Q or navigate the mouse pointer to the menu bar and click ‘Terminal’ > ‘Quit Terminal’. - Go back to the R Console and quit the R application either by:
- Typing
q()
orquit()
behind the R Console prompt (indicated by the>
sign) and pressing return (↩) to execute. - Using the keyboard shortcut: ⌘Q
- Navigating the mouse pointer to the menu bar and clicking ‘R’ > ‘Quit R’
- Navigation the mouse pointer to the top left corner of the R Console window and clicking on the red ball
- Typing
- No matter what you choose, you will always be asked whether you want to save a workspace image as shown in Figure 17 below. Just click on the ‘Don’t Save’ button to end the R application.
- Go back to step 1. of the Configure the R application on macOS section.