Apple Silicon M1: R, radian, python, and RStudio

I recently bought a MacBook Air with the M1 processor and I have had difficulties in rebuilding my coding environment. This post will focus on installing R for Arm64, radian, and RStudio Desktop. My last Mac adventure over 20 years ago had me downloading and installing everything by hand. I have since adopted scripts to automate (and document) my setup. The key to everything is switching to homebrew for installation. This provides the native Arm64 version R which can be used with radian installed through Arm64 conda and allows R to work with the native Arm64 version of RStudio.

Install Xcode from the App store then run:
xcode-select --install
in the default zsh on Mac. I like to use the terminal in VS Code but you can just open the Terminal application that comes on Mac located in the Utilities folder within Applications.

Install brew
/bin/bash -c "$(curl -fsSL"
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
brew update && brew upgrade

Install R for Arm64
brew install r
echo 'alias R="/opt/homebrew/opt/r/bin/R --vanilla"' >> ~/.zshrc

I added this alias because I have never met anyone that wanted to save their workspace.

Install Anaconda/Miniconda3/Miniforge
It took me a while to realize that all the cool kids use conda-forge as their default repository. Miniforge makes this easier.
brew install miniforge
conda init zsh
conda update -y && conda -y --all

At this point, I got stuck. As of this writing, Anaconda/Miniconda did not have an Arm64 installer for macOS so I would need to run in x86 emulation which would not be compatible with Arm64 R and RStudio. Even using the Miniforge Arm64 install, radian 5.11 is listed on conda-forge but is does not install. This is most likely due to the conda-forge Arm64 repository being quite new. The trick is to create a new python environment (in an Arm64 python distribution) and install via pip3.
conda create --name R
conda activate R
pip3 install radian
echo 'alias r="radian"' >> ~/.zshrc && source ~/.zshrc

You should now have python, R, and radian all running on Arm64. I use VS Code on my own but I teach in RStudio. You will need to use the RStudio nightly builds to get Arm64 support. I am sure a stable version will be released in the near future. For those who are interested in VS Code, the vscode-R extension should now work with everything above (although I still haven’t gotten the session watcher to work properly).

Thank you to all the open source folks that make this software freely available. Happy coding!

Author: Probable Pattern

Former Marine and Curious Critter