Skip to content

Commit 406dc4c

Browse files
committed
update r example
1 parent 44bf534 commit 406dc4c

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ for both R and Python.
2323
You can create additional scripts for modularization/better organization
2424
if desired.
2525

26-
2. (If using Python) Update `requirements.txt` with any additional
26+
2. If using Python, update `requirements.txt` with any additional
2727
libraries/packages used by your script(s).
2828

29+
If using R, update `requirements.R` and add/remove any libraries/packages
30+
listed in `pkg_list` that are used by your script(s).
31+
2932
3. (optional) Locally run `run_model.*` to ensure it can run successfully.
3033

3134
These scripts have been written so that the input and output files are not
@@ -49,12 +52,21 @@ for both R and Python.
4952
5053
### Update the Dockerfile
5154
52-
* (If using R) Add any additional packages used by your script(s) to the
53-
installation step.
55+
* Again, make sure that all needed libraries/packages are specified in the
56+
`requirements.*` file. Because all Docker submissions are run without network
57+
access, you will not able to install anything during the container run. If
58+
you do not want to use a `requirements.*` file, you may run replace the RUN
59+
command with the following:
60+
61+
**Python**
62+
```
63+
RUN pip install pandas
64+
```
5465
55-
> **Note** All Docker submissions will be run without network access, so
56-
> you must install all needed dependencies here in the Dockerfile rather
57-
> than in your Rscripts.
66+
**R**
67+
```
68+
RUN R -e "install.packages(c('optparse'), repos = 'http://cran.us.r-project.org')"
69+
```
5870
5971
* `COPY` over any additional files required by your model. We recommend using
6072
one `COPY` command per file, as this can help speed up build time.

r/Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ FROM r-base:4.2.0
77
# commands of the Dockerfile.
88
WORKDIR /usr/local/bin
99

10+
# Copy files over to the image.
11+
# We recommend copying over each file individually, as to take
12+
# advantage of cache building (which helps reduce build time).
13+
COPY requirements.R .
14+
1015
# Install needed libraries/packages.
1116
# Your model will be run without network access, so the dependencies
1217
# must be installed here (and not during code execution).
13-
RUN R -e "install.packages(c('optparse', 'readr', 'tidyr'), repos = 'http://cran.us.r-project.org')"
18+
RUN Rscript requirements.R
1419

15-
# Copy files over to the image.
16-
# We recommend copying over each file individually, as to take
17-
# advantage of cache building (which helps reduce build time).
1820
COPY run_model.R .
1921

2022
# Set the main command of the image.

r/requirements.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if (!suppressWarnings(require("pacman", character.only = TRUE))) {
2+
install.packages("pacman", repos = "http://cran.us.r-project.org")
3+
}
4+
5+
pkg_list <- c("optparse", "readr", "tidyr")
6+
7+
pacman::p_load(pkg_list, character.only = TRUE)

0 commit comments

Comments
 (0)