Skip to content

Commit

Permalink
update r example
Browse files Browse the repository at this point in the history
  • Loading branch information
vpchung committed Jun 13, 2023
1 parent 44bf534 commit 406dc4c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ for both R and Python.
You can create additional scripts for modularization/better organization
if desired.

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

If using R, update `requirements.R` and add/remove any libraries/packages
listed in `pkg_list` that are used by your script(s).

3. (optional) Locally run `run_model.*` to ensure it can run successfully.

These scripts have been written so that the input and output files are not
Expand All @@ -49,12 +52,21 @@ for both R and Python.

### Update the Dockerfile

* (If using R) Add any additional packages used by your script(s) to the
installation step.
* Again, make sure that all needed libraries/packages are specified in the
`requirements.*` file. Because all Docker submissions are run without network
access, you will not able to install anything during the container run. If
you do not want to use a `requirements.*` file, you may run replace the RUN
command with the following:

**Python**
```
RUN pip install pandas
```

> **Note** All Docker submissions will be run without network access, so
> you must install all needed dependencies here in the Dockerfile rather
> than in your Rscripts.
**R**
```
RUN R -e "install.packages(c('optparse'), repos = 'http://cran.us.r-project.org')"
```

* `COPY` over any additional files required by your model. We recommend using
one `COPY` command per file, as this can help speed up build time.
Expand Down
10 changes: 6 additions & 4 deletions r/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ FROM r-base:4.2.0
# commands of the Dockerfile.
WORKDIR /usr/local/bin

# Copy files over to the image.
# We recommend copying over each file individually, as to take
# advantage of cache building (which helps reduce build time).
COPY requirements.R .

# Install needed libraries/packages.
# Your model will be run without network access, so the dependencies
# must be installed here (and not during code execution).
RUN R -e "install.packages(c('optparse', 'readr', 'tidyr'), repos = 'http://cran.us.r-project.org')"
RUN Rscript requirements.R

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

# Set the main command of the image.
Expand Down
7 changes: 7 additions & 0 deletions r/requirements.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if (!suppressWarnings(require("pacman", character.only = TRUE))) {
install.packages("pacman", repos = "http://cran.us.r-project.org")
}

pkg_list <- c("optparse", "readr", "tidyr")

pacman::p_load(pkg_list, character.only = TRUE)

0 comments on commit 406dc4c

Please sign in to comment.