Skip to content

Commit 87777e4

Browse files
committed
update macOS instructions
1 parent 45c87e9 commit 87777e4

File tree

3 files changed

+132
-76
lines changed

3 files changed

+132
-76
lines changed

working_documents/comments_on_install_r_macOS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ I worked through Heather's notes during the RProject Sprint, on Sept 1st
6161
> with the idea that if you had multiple builds of R you could have
6262
> them nested under those directories. Will poll R Contributors to
6363
> help decide what is best.
64+
>
65+
> (gone with second option for now)
6466
6567
3. In Build R, point 3 for Apple Silicon only, in line before `EOF`,
6668
need to add CPPFLAGS to link to the headers for liblzma:
@@ -115,8 +117,7 @@ from `config.site` (it's not needed once gfortran is in the PATH).
115117
--without-recommended-packages
116118
```
117119
118-
> HT: We should try to find a non-hacky way to build with recommended
119-
packages.
120+
> HT: Fixed by updating LDFLAGS. Not sure if this applies to Intel too.
120121
121122
6. Need to install java or turn it off!
122123
@@ -139,5 +140,4 @@ from `config.site` (it's not needed once gfortran is in the PATH).
139140
After `make check`, if still in `build` directory, need to run `bin/R`
140141
to start newly build
141142
142-
> HT: Assume that people will switch with RSwitch/rig and then use RStudio/usual
143-
IDE.
143+
> HT: Fixed by adding `make install` step.

working_documents/install_r_macos.Rmd

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Installing R from Source on macOS"
33
output: github_document
4-
date: "2023-08-11"
4+
date: "2023-12-11"
55
editor_options:
66
markdown:
77
wrap: 72
@@ -13,23 +13,30 @@ knitr::opts_chunk$set(eval = FALSE)
1313

1414
## Prerequisites
1515

16+
Some details and notes are hidden by default - click the black arrowhead to
17+
expand or collapse these sections.
18+
1619
### Set up R installation directory
1720

1821
Open Terminal.app and follow these instructions:
1922

20-
1. Set `LOCAL` as an environment variable to match your architecture
23+
1. Set `LOCAL` as a temporary environment variable to match your architecture
24+
```{sh}
25+
# Intel
26+
export LOCAL=/opt/R/x86_64
27+
```
2128
```{sh}
22-
set LOCAL=/opt/R/x86_64 # Intel
23-
set LOCAL=/opt/R/arm64 # Apple Silicon (e.g. M1)
29+
# Apple Silicon (e.g. M1)
30+
export LOCAL=/opt/R/arm64
2431
```
2532
2. Make your account own `/opt/R` so that we can install prerequisites for
2633
building from source with the helper R script described in the next subsection.
2734
```{sh}
2835
sudo chown -R $USER /opt/R
2936
```
30-
<details><summary>Details</summary> If this is skipped, get errors when
31-
running `install.libs("r-base-dev")`, e.g. " Can't restore time",
32-
"Can't unlink already-existing object"
37+
<details><summary><i>Details...</i></summary> If this is skipped, you get errors when
38+
running `install.libs("r-base-dev")`, e.g. "Can't restore time",
39+
"Can't unlink already-existing object".
3340
</details>
3441
3. Add `$LOCAL/bin` to your path
3542
```{sh}
@@ -38,17 +45,17 @@ cat << EOF >> /Users/$USER/.zprofile
3845
export PATH="$LOCAL/bin:\${PATH}"
3946
EOF
4047
```
48+
<details><summary><i>Note if using RStudio terminal, or using Terminal.app on macOS < 10.15 (Catalina)...</i></summary> The code above assumes you are using a Zsh shell (the default on macOS &ge; 10.15). If you are using a bash shell, replace <code>.zprofile</code> with <code>.bash_profile</code>. The type of terminal in RStudio can be set in Terminal Options from the terminal or in Global Options.
49+
</details>
50+
</details>
4151
4. If you have previously installed R on the computer, make your account own the existing R framework folder
4252
```{sh}
4353
sudo chown -R $USER /Library/Frameworks/R.framework/
4454
```
45-
Otherwise, download the installer for the latest release of R from CRAN and install with the default settings.
55+
Otherwise, download the installer for the latest release of R from CRAN and install with the default settings first.
4656

4757
### Install prerequisites
4858

49-
It is best to install prerequisites before first building R from source,
50-
even if you think you may have installed some of the prerequisites before.
51-
5259
1. Install Xcode Command Line Tools from the terminal
5360
```{sh}
5461
xcode-select --install
@@ -69,25 +76,34 @@ install.libs("r-base-dev")
6976
```{r}
7077
install.libs("pango")
7178
```
72-
6. TODO, guidance for installing MacTex for those that need it
79+
6. Check if you have a current version of MacTeX installed:
80+
```{sh}
81+
ls /usr/local/texlive
82+
```
83+
If the `/usr/local/texlive` directory exists, you will see one or more subdirectories named by year, e.g.
84+
```
85+
2022 2023 texmf-local
86+
```
87+
If this check doesn't show a subdirectory for the current year, install MacTex from the binary at <https://tug.org/mactex/mactex-download.html>.
7388
7. In the terminal, check if you already have Subversion installed:
7489
7590
```{sh}
7691
which svn
7792
```
7893
79-
This with show a path where Subversion is installed, or `svn not found`.
94+
This will show a path where Subversion is installed, or `svn not found`.
8095
If necessary, install Subversion from within R:
8196
8297
```{r}
8398
install.libs("subversion", dep = FALSE)
8499
```
85100
86-
<details><summary>Troubleshooting</summary> If this does not work, try installing via your preferred package manage, e.g. with Homebrew: <code>brew install svn</code>.
101+
<details><summary><i>Troubleshooting...</i></summary> If this does not work, try installing via your preferred package manage, e.g. with Homebrew: <code>brew install svn</code>.
87102
</details>
88103
89104
8. (Recommended) If you are not already using a tool such as [rig](https://github.com/r-lib/rig)
90-
to install and manage multiple R versions, install RSwitch from <https://rud.is/rswitch/>.
105+
to install and manage multiple R versions, install RSwitch from <https://rud.is/rswitch/>. These tools are not part of the R Project, but
106+
make it easy to switch R versions.
91107
92108
[//]: # (
93109
* Skip readline (use editline)
@@ -105,9 +121,6 @@ dependencies at same time
105121
106122
Run the following commands within Terminal.app:
107123
108-
<details><summary>Note if you prefer to use an RStudio terminal</summary> The PATH setting in <code>~/.zprofile</code> will only work for a zsh terminal, so you may need to change your Global Options or add the PATH setting to <code>~/.bash_profile</code>
109-
</details>
110-
111124
0. Retrieve R source code into `TOP_SRCDIR`, note that we retrieve the `r-devel` source code:
112125
```{sh}
113126
export TOP_SRCDIR="$HOME/svn/R-devel"
@@ -121,9 +134,9 @@ $TOP_SRCDIR/tools/rsync-recommended
121134
122135
2. Create the build directory in the `BUILDDIR`:
123136
```{sh}
124-
export BUILDDIR="$HOME/bin/R"
125-
mkdir -p "$BUILDDIR"
126-
cd "$BUILDDIR"
137+
export BUILDDIR="$HOME/build/R-devel"
138+
mkdir -p $BUILDDIR
139+
cd $BUILDDIR
127140
```
128141
129142
3. Create `config.site` within the build directory to set some configuration flags as recommended by the [R-admin manual](https://cran.r-project.org/doc/manuals/r-devel/R-admin.html#Prerequisites).
@@ -143,18 +156,18 @@ cat << EOF >> config.site
143156
CFLAGS="-falign-functions=8 -g -O0"
144157
FFLAGS="-g -O2 -mmacosx-version-min=11.0"
145158
FCFLAGS="-g -O2 -mmacosx-version-min=11.0"
146-
LDFLAGS=-L$LOCAL/lib
159+
LDFLAGS="-L$LOCAL/lib -L/opt/gfortran/lib"
147160
CPPFLAGS="-isystem $LOCAL/include -I$LOCAL/include"
148161
EOF
149162
```
150-
<details><summary>Details</summary> Some modifications to th: `-O0` to enable debugging symbols and disable compiler optimisations for better debugging experience; `-mmacos-version-min` corrected [?] to `-mmacosx-version-min`; `LDFLAGS=-L$LOCAL/lib` added so that liblzma can be found. CPPFLAGS modified for Apple Silicon to link to the headers for liblzma.
163+
<details><summary><i>Details...</i></summary> Some modifications to the recommendations in R-admin: `-O0` to enable debugging symbols and disable compiler optimisations for better debugging experience; `-mmacos-version-min` corrected [?] to `-mmacosx-version-min`; `LDFLAGS="-L$LOCAL/lib -L/opt/gfortran/lib"` added so that liblzma (in `$LOCAL/lib`) and gfortran libraries can be found. CPPFLAGS modified for Apple Silicon to link to the headers for liblzma.
151164
</details>
152165
153-
4. Configure the R installation with `--enable-R-framework` to install as an application framework so that we can switch between R versions with Rswitch:
166+
4. Configure the R installation with `--enable-R-framework` to install as an application framework so that we can switch between R versions with RSwitch:
154167
```{sh}
155168
"$TOP_SRCDIR/configure" --enable-R-framework
156169
```
157-
<details><summary>Details</summary> This assumes you only want to work with one development version of R that will be identified by the Major.Minor version number. To customize the version name use `--enable-R-framework FW=VERSION` where e.g. VERSION=4.4-dev. The compilation options in [R-admin manual](https://cran.r-project.org/doc/manuals/r-devel/R-admin.html#Prerequisites) to define the location of X11 and tcltk libraries do not seem to be necessary.
170+
<details><summary><i>Working with multiple devel versions...</i></summary> The code above assumes you only want to work with one development version of R that will be identified by the Major.Minor version number. To customize the version name use `--enable-R-framework FW=VERSION` where e.g. `VERSION=4.4-dev`. The configure options in [R-admin manual](https://cran.r-project.org/doc/manuals/r-devel/R-admin.html#Prerequisites) to define the location of X11 and tcltk libraries do not seem to be necessary.
158171
</details>
159172
160173
5. Build R :
@@ -166,7 +179,11 @@ make
166179
make check
167180
```
168181
`make` will exit with an error if there are any problems.
169-
<details><summary>Note if you are using RStudio terminal</summary> `make check` will fail unless you run `unset R_HOME` first
182+
<details><summary><i>Note if you are using RStudio terminal...</i></summary> `make check` will fail unless you run `unset R_HOME` first
170183
</details>
171-
172-
The built version of R will now be your default version of R. To switch versions, use RSwitch or rig.
184+
7. Install the built version of R
185+
```{sh}
186+
make install
187+
```
188+
189+
The built version of R will now be your default version of R, which you can start by typing `R` in the terminal, or restarting the R session in RStudio, etc. To switch versions, use RSwitch or rig, then restart your R session.

0 commit comments

Comments
 (0)