@@ -18,6 +18,11 @@ environment based on containerized solutions leveraging the
18
18
of multiple dockerized development flavors, to match various target production
19
19
environments or projects.
20
20
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
+
21
26
22
27
## Version-stable deployments
23
28
@@ -67,15 +72,15 @@ different projects for which such version is relevant. For this reason, a
67
72
sensible choice is to rely on ` rocker/verse ` images, which add tidyverse and
68
73
devtools to the stack. They also include R Markdown system
69
74
dependencies TinyTeX and pandoc, sparing the effort of the tedious extra
70
- install. See the specific section below about 'TinyTeX considerations'.
75
+ install.
71
76
72
77
73
78
### Running versioned RStudio instances
74
79
75
80
Assume we want to run a containerized versioned instance of RStudio for R 4.4.1,
76
81
possibly alongside instances for other versions of R.
77
82
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:
79
84
``` {bash pull}
80
85
docker pull rocker/verse:4.4.1
81
86
```
@@ -87,17 +92,20 @@ following setup:
87
92
- Enable root by setting the environment variable ` ROOT ` to ` TRUE ` , so that e.g.
88
93
` sudo apt-get ` can be used in RStudio.
89
94
- 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 ) ).
91
98
- The development code of all relevant projects should live outside the
92
99
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
94
101
the container.
95
102
- For this to work w/o [ permission
96
103
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.
98
106
- In order for the RStudio settings to persist if the container is recreated
99
107
(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
101
109
version-specific in case of multiple R versions.
102
110
- If we want to use Meld via the [ compareWith] ( https://github.com/miraisolutions/compareWith/ ) addins, we need to
103
111
- map the ` DISPLAY ` environment variable and volume ` /tmp/.X11-unix ` ,
@@ -110,15 +118,15 @@ e.g. `rstudio_4.4.1`.
110
118
111
119
``` {bash run}
112
120
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
115
123
docker run -d --restart=always \
116
124
-p 127.0.0.1:$(echo $R_VER | sed 's/[.]//g')0:8787 \
117
125
-e DISABLE_AUTH=true \
118
126
-e ROOT=TRUE \
119
127
-e USERID=$UID \
120
128
-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 \
122
130
-e DISPLAY=$DISPLAY \
123
131
-v /tmp/.X11-unix:/tmp/.X11-unix:ro \
124
132
--name rstudio_$R_VER \
@@ -130,7 +138,7 @@ docker exec rstudio_$R_VER bash -c \
130
138
docker exec rstudio_$R_VER bash -c \
131
139
'apt-get update && apt-get install -y --no-install-recommends meld dbus-x11'
132
140
```
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/ ` .
134
142
135
143
You may find convenient to define a shell function for these steps:
136
144
@@ -146,14 +154,14 @@ run_rstudio_ver() {
146
154
"based on image "$BASE_IMAGE\
147
155
"with shared volume "$SHARED_DIR
148
156
docker pull $BASE_IMAGE &&
149
- mkdir -p $HOME/.rstudio-docker /$R_VER &&
157
+ mkdir -p $HOME/.rstudio-config /$R_VER &&
150
158
docker run -d --restart=always \
151
159
-p 127.0.0.1:$PORT:8787 \
152
160
-e DISABLE_AUTH=true \
153
161
-e ROOT=TRUE \
154
162
-e USERID=$UID \
155
163
-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 \
157
165
-e DISPLAY=$DISPLAY \
158
166
-v /tmp/.X11-unix:/tmp/.X11-unix:ro \
159
167
--name $CONTAINER_NAME \
@@ -171,7 +179,7 @@ run_rstudio_ver() {
171
179
172
180
which you can re-use as compact command for any R version:
173
181
``` {bash run_rstudio_ver-use}
174
- run_rstudio_ver 4.4.1 RStudioProjects
182
+ run_rstudio_ver 4.4.1 workspace
175
183
```
176
184
177
185
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.
198
206
which is then mapped to the user that invoked the podman command when writing files to the shared volume.
199
207
Because of this, RStudio does not set the desired home directory as the initial working directory. To correct this, add
200
208
```
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 &&
202
210
```
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.
204
212
If you run into issues, the discussion in this rocker [ pull request] ( https://github.com/rocker-org/rocker-versioned2/pull/636 )
205
213
about rootless container support may help.
206
214
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,
210
218
as these seem to be the most regularly updated images
211
219
(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
- ```
261
220
262
221
263
222
### Cleanup
@@ -273,3 +232,4 @@ docker rm $(docker stop rstudio_4.4.1)
273
232
- [ Shared Volumes] ( https://www.rocker-project.org/use/shared_volumes/ )
274
233
- [ Rocker Wiki] ( https://github.com/rocker-org/rocker/wiki )
275
234
- [ 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