Skip to content

Instantly share code, notes, and snippets.

@emmamendelsohn
Last active December 15, 2023 17:16
Show Gist options
  • Save emmamendelsohn/49144f85393b4e45125f779c6f91eb68 to your computer and use it in GitHub Desktop.
Save emmamendelsohn/49144f85393b4e45125f779c6f91eb68 to your computer and use it in GitHub Desktop.
---
title: "Enabling R Package Install on Silicon Macs"
date: "`r Sys.Date()`"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
This documents some of the troubleshooting performed by Nate and Emma on project setup with M1 macs. Updated Dec 15, 2023 with latest gcc install.
1. Install the R compilation tool chain https://mac.thecoatlessprofessor.com/macrtools/. If any issues with FORTRAN, follow instructions for downloading FORTRAN compiler here for Apple silicon Macs: <https://mac.r-project.org/tools/>
2. Install gcc `brew install gcc`. This requires having brew set up.
3. Make sure homebrew is in terminal path. Add it by `export PATH=$PATH:/opt/homebrew/bin`.
4. Create `~/.R/Makevars` and insert the following. This will need to be updated depending on gcc version.
CXX14FLAGS += -O3 -arch arm64 -ftemplate-depth-256
FC = /opt/homebrew/Cellar/gcc/13.2.0/bin/gfortran
F77 = /opt/homebrew/Cellar/gcc/13.2.0/bin/gfortran
FLIBS = -L/opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/13
5. RStudio may have a bug in accessing the correct terminal path. The workaround is to copy your terminal path (`echo $PATH`) into `.Renviron` per instructions here: <https://community.rstudio.com/t/how-to-get-rstudio-ide-to-use-the-correct-terminal-path-in-mac-os-x/131528/6>
6. Some packages may need additional help for R to find the correct paths. For `units`:
`remotes::install_version(package = "units",
version = "0.8-5",
configure.args = "--with-udunits2-lib=/opt/homebrew/Cellar/udunits/2.2.28/lib --with-udunits2-include=/opt/homebrew/Cellar/udunits/2.2.28/include")`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment