Skip to content

Commit 8b6ad20

Browse files
committed
Incorporate PR feedback
1 parent 5ad554c commit 8b6ad20

File tree

1 file changed

+27
-67
lines changed

1 file changed

+27
-67
lines changed

version-stable-r-development.Rmd

+27-67
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ environment based on containerized solutions leveraging the
1818
of multiple dockerized development flavors, to match various target production
1919
environments or projects.
2020

21+
> _The instructions in this chapter are for R >= 4.0.0.
22+
Images for R <= 3.6.3 are defined in
23+
[rocker-org/rocker-versioned](https://github.com/rocker-org/rocker-versioned),
24+
but are no longer actively maintained._
25+
2126

2227
## Version-stable deployments
2328

@@ -67,15 +72,15 @@ different projects for which such version is relevant. For this reason, a
6772
sensible choice is to rely on `rocker/verse` images, which add tidyverse and
6873
devtools to the stack. They also include R Markdown system
6974
dependencies TinyTeX and pandoc, sparing the effort of the tedious extra
70-
install. See the specific section below about 'TinyTeX considerations'.
75+
install.
7176

7277

7378
### Running versioned RStudio instances
7479

7580
Assume we want to run a containerized versioned instance of RStudio for R 4.4.1,
7681
possibly alongside instances for other versions of R.
7782

78-
First of all, we need to get the image from docker-hub
83+
First of all, we need to get the image from docker-hub:
7984
```{bash pull}
8085
docker pull rocker/verse:4.4.1
8186
```
@@ -87,17 +92,20 @@ following setup:
8792
- Enable root by setting the environment variable `ROOT` to `TRUE`, so that e.g.
8893
`sudo apt-get` can be used in RStudio.
8994
- Use a version-specific port, e.g. `4000` for R 4.0.0, `4410` for R 4.4.1 and
90-
so on, so that we can use `localhost` for concurrent R version instances.
95+
so on, so that we can use `localhost` for concurrent R version instances.
96+
We bind the port to localhost (`127.0.0.1:4410`), so it is only accessible locally
97+
(see [the Rocker reference](https://rocker-project.org/images/versioned/rstudio.html#disable_auth)).
9198
- The development code of all relevant projects should live outside the
9299
container and be shared with it (and possibly multiple other containers), e.g. under
93-
`~/RStudioProjects` on the host machine and `/home/rstudio/RStudioProjects` in
100+
`~/workspace` on the host machine and `/home/rstudio/workspace` in
94101
the container.
95102
- For this to work w/o [permission
96103
issues](https://github.com/rocker-org/rocker/wiki/Sharing-files-with-host-machine#avoiding-permission-changes-when-sharing-volumes),
97-
the container user (`rstudio`) must match the UID of the host user (`$UID`).
104+
the container user (`rstudio`) must match the UID of the host user (`$UID`).
105+
This has the effect of setting the ownership of `~/workspace` on the host machine to `$UID` if it is not already owned by that user.
98106
- In order for the RStudio settings to persist if the container is recreated
99107
(e.g. after pulling a new `rocker` image), we also use a shared volume (like
100-
`~/.rstudio-docker/4.4.1`) for the `home/rstudio/.config/rstudio` directory, which is
108+
`~/.rstudio-config/4.4.1`) for the `/home/rstudio/.config/rstudio` directory, which is
101109
version-specific in case of multiple R versions.
102110
- If we want to use Meld via the [compareWith](https://github.com/miraisolutions/compareWith/) addins, we need to
103111
- map the `DISPLAY` environment variable and volume `/tmp/.X11-unix`,
@@ -110,15 +118,15 @@ e.g. `rstudio_4.4.1`.
110118

111119
```{bash run}
112120
R_VER=4.4.1
113-
SHARED_DIR=RStudioProjects
114-
mkdir -p $HOME/.rstudio-docker/$R_VER
121+
SHARED_DIR=workspace
122+
mkdir -p $HOME/.rstudio-config/$R_VER
115123
docker run -d --restart=always \
116124
-p 127.0.0.1:$(echo $R_VER | sed 's/[.]//g')0:8787 \
117125
-e DISABLE_AUTH=true \
118126
-e ROOT=TRUE \
119127
-e USERID=$UID \
120128
-v $HOME/$SHARED_DIR:/home/rstudio/$SHARED_DIR \
121-
-v $HOME/.rstudio-docker/$R_VER:/home/rstudio/.config/rstudio \
129+
-v $HOME/.rstudio-config/$R_VER:/home/rstudio/.config/rstudio \
122130
-e DISPLAY=$DISPLAY \
123131
-v /tmp/.X11-unix:/tmp/.X11-unix:ro \
124132
--name rstudio_$R_VER \
@@ -130,7 +138,7 @@ docker exec rstudio_$R_VER bash -c \
130138
docker exec rstudio_$R_VER bash -c \
131139
'apt-get update && apt-get install -y --no-install-recommends meld dbus-x11'
132140
```
133-
If you are using R_VER=4.4.1, the running RStudio can then be accessed by visiting `http://localhost:4410/`.
141+
If you are using `R_VER=4.4.1`, the running RStudio can then be accessed by visiting `http://localhost:4410/`.
134142

135143
You may find convenient to define a shell function for these steps:
136144

@@ -146,14 +154,14 @@ run_rstudio_ver() {
146154
"based on image "$BASE_IMAGE\
147155
"with shared volume "$SHARED_DIR
148156
docker pull $BASE_IMAGE &&
149-
mkdir -p $HOME/.rstudio-docker/$R_VER &&
157+
mkdir -p $HOME/.rstudio-config/$R_VER &&
150158
docker run -d --restart=always \
151159
-p 127.0.0.1:$PORT:8787 \
152160
-e DISABLE_AUTH=true \
153161
-e ROOT=TRUE \
154162
-e USERID=$UID \
155163
-v $HOME/$SHARED_DIR:/home/rstudio/$SHARED_DIR \
156-
-v $HOME/.rstudio-docker/$R_VER:/home/rstudio/.config/rstudio \
164+
-v $HOME/.rstudio-config/$R_VER:/home/rstudio/.config/rstudio \
157165
-e DISPLAY=$DISPLAY \
158166
-v /tmp/.X11-unix:/tmp/.X11-unix:ro \
159167
--name $CONTAINER_NAME \
@@ -171,7 +179,7 @@ run_rstudio_ver() {
171179

172180
which you can re-use as compact command for any R version:
173181
```{bash run_rstudio_ver-use}
174-
run_rstudio_ver 4.4.1 RStudioProjects
182+
run_rstudio_ver 4.4.1 workspace
175183
```
176184

177185
Note that `--restart=always` specifies that the container should stay up and restart
@@ -198,66 +206,17 @@ This is why we use a mounted volume for the `~/.config/rstudio` directory.
198206
which is then mapped to the user that invoked the podman command when writing files to the shared volume.
199207
Because of this, RStudio does not set the desired home directory as the initial working directory. To correct this, add
200208
```
201-
echo '{ "initial_working_directory": "/home/rstudio" }' > $HOME/.rstudio-docker/$R_VER/rstudio-prefs.json &&
209+
echo '{ "initial_working_directory": "/home/rstudio" }' > $HOME/.rstudio-config/$R_VER/rstudio-prefs.json &&
202210
```
203-
After `mkdir -p $HOME/.rstudio-docker/$R_VER` in the `run_rstudio_ver` function.
211+
After `mkdir -p $HOME/.rstudio-config/$R_VER` in the `run_rstudio_ver` function.
204212
If you run into issues, the discussion in this rocker [pull request](https://github.com/rocker-org/rocker-versioned2/pull/636)
205213
about rootless container support may help.
206214

207-
### Supported R versions
208-
This tutorial uses images based on the [rocker-versioned2](https://github.com/rocker-org/rocker-versioned2) repository,
209-
which provides images for R >= 4.0. We recommend using the latest patch version for each minor version - e.g. 4.0.5 for 4.0.x,
215+
### Best-supported R versions
216+
This tutorial uses images based on the [rocker-versioned2](https://github.com/rocker-org/rocker-versioned2) repository.
217+
We recommend using the latest patch version for each minor version - e.g. 4.0.5 for 4.0.x,
210218
as these seem to be the most regularly updated images
211219
(see e.g. [rocker/verse on docker hub](https://hub.docker.com/r/rocker/verse/tags?page=&page_size=&ordering=&name=4.0.)).
212-
When using older images based on the [previous version](https://github.com/rocker-org/rocker-versioned) of the repository,
213-
the settings are saved in _/home/rstudio/.rstudio_, so the settings mount is different: `-v $HOME/.rstudio-docker/$R_VER:/home/rstudio/.rstudio`
214-
215-
### TinyTeX considerations
216-
217-
#### `pdfcrop`
218-
219-
Older `rocker/verse` images might not include `pdfcrop`, which is required for
220-
the default and desirable cropping of PDF figures with R Markdown (see
221-
[rocker-org/rocker-versioned#146](https://github.com/rocker-org/rocker-versioned/issues/146)).
222-
Make sure `pdfcrop` is installed by running the following in the R console:
223-
```{r pdfcrop}
224-
tinytex::tlmgr_install("pdfcrop")
225-
```
226-
(see [R Markdown: The Definitive
227-
Guide](https://bookdown.org/yihui/rmarkdown/pdf-document.html#figure-options-1))
228-
229-
#### Align TinyTeX to current remote repo
230-
231-
**NOTE** - This should never be needed with recent `rocker/verse` images, where
232-
a version-stable Tex Live repository is used for the TinyTeX install (see
233-
[rocker-org/rocker-versioned#169](https://github.com/rocker-org/rocker-versioned/issues/169)).
234-
235-
If you are using LaTeX and start seeing errors like
236-
```
237-
Remote repository is newer than local (2018 < 2019)
238-
```
239-
you have to re-install TinyTeX. This happens e.g. with
240-
`rocker/verse:3.6.1`, since it was build at the end of 2018 but the current
241-
Tex Live repo is 2019. You can fix this via a **user-specific** re-installation of
242-
TinyTeX for R. **NOTE** however that this will uninstall the system-level
243-
TinyTeX pre-installed in `rocker/verse`.
244-
245-
First, make sure `/home/rstudio/bin` is part of the `PATH` environment variable.
246-
Check this by running
247-
```{bash check-path}
248-
docker exec --user rstudio rstudio_3.6.1 R --slave -e 'Sys.getenv("PATH")'
249-
```
250-
If you don't see `/home/rstudio/bin`, you can make sure it is part of the `PATH` for R via
251-
```{bash set-path}
252-
docker exec --user rstudio rstudio_3.6.1 sh -c 'echo "PATH=$HOME/bin:\${PATH}" >> $HOME/.Renviron'
253-
# check again
254-
docker exec --user rstudio rstudio_3.6.1 R --slave -e 'Sys.getenv("PATH")'
255-
```
256-
257-
Then, from the running RStudio, run
258-
```{r reinstall-tinytex}
259-
tinytex::reinstall_tinytex()
260-
```
261220

262221

263222
### Cleanup
@@ -273,3 +232,4 @@ docker rm $(docker stop rstudio_4.4.1)
273232
- [Shared Volumes](https://www.rocker-project.org/use/shared_volumes/)
274233
- [Rocker Wiki](https://github.com/rocker-org/rocker/wiki)
275234
- [Sharing files with host machine](https://github.com/rocker-org/rocker/wiki/Sharing-files-with-host-machine)
235+
- [Rocker reference for verse and other images](https://rocker-project.org/images/versioned/rstudio.html) (in particular [how to use](https://rocker-project.org/images/versioned/rstudio.html#how-to-use))

0 commit comments

Comments
 (0)