forked from r-hub/r-minimal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
244 lines (185 loc) · 8.18 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
---
output: github_document
editor_options:
markdown:
wrap: 72
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
out.width = "100%"
)
```
# Minimal Docker images for R
## What is R?
R is a free software environment for statistical computing and graphics.
It compiles and runs on a wide variety of UNIX platforms, Windows and
MacOS. See more at https://www.r-project.org/
## Goals and features
The main goal of these images is to keep them minimal, so they can be used
as part of a bigger (web) application, or as a base image. Currently the
(R 4.1.0) `r-minimal` image is less than 21MB compressed, and 35.4MB
uncompressed.
All images use Alpine Linux.
The images include the `installr` tools that can install R packages from
CRAN or GitHub:
```
❯ installr -h
Usage: ./installr [ -c | -d ] [ -e ] [ -a pkgs ] [ -t pkgs ] [ -r ] [ -p ] REMOTES ...
Options:
-c install C and C++ compilers and keep them
-d install C and C++ compilers, temporarily
-a install Alpine packages and keep them
-t install Alpine packages, temporarily
-p do not remove pak after the installation (ignored if -r is given).
-e use renv to restore the renv.lock file if present.
REMOTES may be:
* package names from CRAN/Bioconductor, e.g. ggplot2
* slugs of GitHub repos, e.g. tidyverse/ggplot2
* GitHub branch, tag or commit, e.g tidyverse/[email protected]
* URLs to package .tar.gz files, e.g. url::https://x.com/pkg.tar.gz
* path to a local directory, e.g. local::.
```
Recent r-minimal containers use pak (https://github.com/r-lib/pak) for R
packages installation. If you have problems with pak, or need to install
a package from a source that pak does not support, but the remotes package
does, then install the remotes package first.
## Limitations
To keep the images minimal, they do not include a number of parts and
features that most users would prefer to have for interactive R
development:
* Recommended R packages are not installed.
* Documentation is not included.
* No X11 support.
* No OpenMP support.
* No JPEG, PNG or TIFF support.
* No Cairo support.
* No Tcl/Tk support.
* No translations, only English.
* The image does not have C, C++ or Fortran compilers.
* Limited time zone data: `GMT`, `UTC` and `America/New_York`, see
below if you need better time zone data.
## Usage
Get the image from
[Docker Hub](https://hub.docker.com/repository/docker/rhub/r-minimal):
```
docker pull docker.io/rhub/r-minimal:latest
```
or from [GitHub Packages](https://github.com/r-hub/r-minimal/packages/92808?version=latest):
```
docker pull docker.pkg.github.com/r-hub/r-minimal/r-minimal:latest
```
## Platforms
All images are available on `linux/amd64` and `linux/arm64` platforms.
## Supported R versions
Currently we support the last patch version of the last five minor R
versions. The `latest` tag always uses the last R release.
```{r, include = FALSE}
source("tools/calculate_tags.R")
```
image | R version | tags | note
----------| ------------------|----------------------- | -----------
R devel | `r rv("devel")` | `r rv_tags("devel")` | Built daily
R next | `r rv("next")` | `r rv_tags("next")` | Built daily
R release | `r rv("release")` | `r rv_tags("release")` |
R 4.2.x | `r rv("4.2")` | `r rv_tags("4.2")` |
R 4.1.x | `r rv("4.1")` | `r rv_tags("4.1")` |
R 4.0.x | `r rv("4.0")` | `r rv_tags("4.0")` |
R 3.6.x | `r rv("3.6")` | `r rv_tags("3.6")` |
R 3.5.x | `r rv("3.5")` | `r rv_tags("3.5")` |
## Dockerfile examples
One of our main goals is to be able to use `rhub/r-minimal` as a base
image, and easily add R packages from CRAN or GitHub to it, to create a
new image. Run `installr` from a `Dockerfile` to add R packages to
the `r-minimal` image:
```
FROM rhub/r-minimal
RUN installr praise
CMD [ "R", "--slave", "-e", "cat(praise::praise())" ]
```
Package with compiled code:
```
FROM rhub/r-minimal
RUN installr -d glue
```
After the package(s) have been installed, `installr` removed the compilers,
as these are typically not needed on the final image. If you want to keep
them use `installr -c` instead of `installr -d`.
Package with system requirements:
```
FROM rhub/r-minimal
RUN installr -d -t linux-headers pingr
CMD [ "R", "-q", "-e", "pingr::is_online() || stop('offline')" ]
```
Similarly to compilers, system packages are removed after the R packages
have been installed. If you want to keep (some of) them, use `installr -a`
instead of `installr -t`. (You can also mix the two.)
Using with renv:
To use `renv` to restore the `renv.lock` file, use the `-e` option:
```
FROM rhub/r-minimal
COPY .Rprofile .Rprofile
COPY renv renv
COPY renv.lock .
RUN installr -d -e
```
If you copy the entire folder with renv, including the `activate.R` and `.Rprofile`, renv will bootstrap itself with the same version as the lock and restore the packages with the proper versions.
All the necessary compilers and libraries needed at runtime need to be installed with the `-a` and `-t` options.
Please refer to examples/renv-shiny for an example that install shiny and rmarkdown in a container.
## Popular packages:
Hints on installing some popular R packages:
package | installr command | ~ image size
--------------- | --------------------------------------------------------- | -------------
data.table | `installr -d data.table` | 39.1 MB
dplyr | `installr -d dplyr` | 47.8 MB
ggplot2 | `installr -d -t gfortran ggplot2` | 82.1 MB
h2o | See `examples/h2o`. | 408.0 MB
knitr | `installr -d knitr` | 79.2 MB
shiny | See `examples/shiny`. | 84.1 MB
sf | See `examples/sf`. | 184.5 MB
plumber | See `examples/plumber`. | 103.1 MB
rmarkdown | `installr -d rmarkdown` | 161.3 MB (including pandoc)
rstan | See `examples/rstan`. | 344.4 MB
tidyverse | See `examples/tidyverse`. | 182.4 MB
xgboost | `installr -d -t "gfortran libexecinfo-dev" -a libexecinfo xegboost` | 59.9 MB
See also the `Dockerfile`s in the `examples` directory.
> Note that package and system dependencies change over time, so if any
> of these commands do not work any more, please
> [let us know](https://github.com/r-hub/r-minimal).
> See the [examples/rmarkdown/Dockerfile] for installing pandoc.
## Time zones
The image uses R's internal time zone database, but most time zones are
removed from, to save space. The only supported ones are `GMT`, `UTC` and
`America/New_York`. If you need more time zones, then install Alpine's
time zone package and point R to it:
```
apk add --no-cache tzdata
export TZDIR=/usr/share/zoneinfo
```
See also the discussion at https://github.com/r-hub/r-minimal/issues/24
## Known failures and workarounds
* The ps package needs the `linux-headers` Alpine package at compile time.
Many tidyverse packages depend on ps, so they'll need it as well:
```
installr -d -t linux-headers ps
```
* The arrow package needs a `Makevars` file to add a link flag. See the
example `Dockerfile` in the `examples/arrow` directory.
* The V8 packagees do not compile on aarch64 machines by default.
On x86_64 it installs fine:
```
installr -d -t curl-dev V8
```
This means that other packages that need V8 (e.g. rstan and prophet)
do not work on aarch64, either.
* To install the magick package, you need both the `imagemagick` and
`imagemagick-dev` Alpine packages, both at install time and run time:
```
installr -d -a "imagemagick imagemagick-dev" -t "curl-dev" magick
```
## License
See https://www.r-project.org/Licenses/ for the R licenses
These Dockerfiles are licensed under the MIT License.
© [R Consortium](https://github.com/rconsortium)