Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up renv usage to fix incompatibility between stored CRAN repositories and renv version. update README.md files. regenerate renv.lock files #29

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rocker/r-ver:4.3.2
FROM rocker/r-ver:4.4.1

# install general OS utilities
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand Down Expand Up @@ -76,7 +76,8 @@ RUN pip3 install -r requirements.txt
# install required R packages using renv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# install required R packages using renv
# install required R packages using renv
# see https://rstudio.github.io/renv/articles/docker.html

COPY "${MODEL_DIR}/renv.lock" ./
ENV RENV_PATHS_LIBRARY="renv/library"
RUN Rscript -e "install.packages('renv', repos = c(CRAN = 'https://cloud.r-project.org'))"
RUN /rocker_scripts/setup_R.sh https://p3m.dev/cran/__linux__/jammy/2025-02-05
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding comments for reference

Suggested change
RUN /rocker_scripts/setup_R.sh https://p3m.dev/cran/__linux__/jammy/2025-02-05
# Guidance for setting default CRAN mirror: https://rocker-project.org/images/versioned/r-ver.html#switch-the-default-cran-mirror
# Posit Public Package Manager setup: https://p3m.dev/client/#/repos/cran/setup
RUN /rocker_scripts/setup_R.sh https://p3m.dev/cran/__linux__/jammy/2025-02-05

RUN Rscript -e "install.packages('renv')"
RUN Rscript -e "renv::restore()"

# clone https://github.com/reichlab/container-utils. ADD is a hack ala https://stackoverflow.com/questions/35134713/disable-cache-for-specific-run-commands
Expand Down
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,34 @@ Generating this file is somewhat Python tooling-specific. For example, [pipenv](

A `renv.lock` file is generated via the following steps. As noted above, the "install required R libraries via CRAN" step will vary depending on the individual model's needs. Below we show the commands for the `flu_ar2` model, but you will need to change them for yours.

- start a fresh temporary [rocker/r-ver:4.3.2](https://hub.docker.com/layers/rocker/r-ver/4.3.2/images/sha256-8b25859fbf21a7075bbc2285ebfe06bb8a14dd83e4576df11ff46f14a8620636?context=explore) container via `docker run --rm -it --name temp_container rocker/r-ver:4.3.2 /bin/bash`
- install the required OS libraries and applications (see "install general OS utilities" and "install OS binaries required by R packages" in the [Dockerfile](Dockerfile))
- install renv via `Rscript -e "install.packages('renv', repos = c(CRAN = 'https://cloud.r-project.org'))"`
- create a project directory via `mkdir /proj ; cd /proj`
- initialize renv via `Rscript -e "renv::init(bare = TRUE)"`
- install required R libraries. NB: these will vary depending on the model (see each model's `README.md` for the actual list). For example:
1. start a fresh temporary [rocker/r-ver:4.4.1](https://hub.docker.com/layers/rocker/r-ver/4.4.1/images/sha256-f3ef082e63ca36547fcf0c05a0d74255ddda6ca7bd88f1dae5a44ce117fc3804) container via:
```bash
docker run --rm -it --name temp_container rocker/r-ver:4.4.1 /bin/bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rocker containers are built on amd64 and if you don't specify a platform, you get this lovely warning on arm Macs:

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Suggested change
docker run --rm -it --name temp_container rocker/r-ver:4.4.1 /bin/bash
docker run --platform linux/amd64 --rm -it --name temp_container rocker/r-ver:4.4.1 /bin/bash

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rocker containers are built on amd64 and if you don't specify a platform, you get this lovely warning on arm Macs: ...

Thanks for the heads up. Interestingly, I don't see that warning on my Mac. Generally I've been omitting the --platform flag and assuming the reader knows which to use, with the exception of the "To publish the image" section, where I specify amd64.

```
2. install the required OS libraries and applications (see "install general OS utilities" and "install OS binaries required by R packages" in the [Dockerfile](Dockerfile))
3. specify repo via:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3. specify repo via:
3. specify the [p3m repository snapshot to a particular date](https://p3m.dev/client/#/repos/cran/setup?distribution=ubuntu-22.04&r_environment=other&snapshot=2025-02-05) (this allows binary packages to be installed for faster builds) (see the [rocker-project guidance for switching the default CRAN mirror](https://rocker-project.org/images/versioned/r-ver.html#switch-the-default-cran-mirror)

```bash
/rocker_scripts/setup_R.sh https://p3m.dev/cran/__linux__/jammy/2025-02-05
```
4. install renv via:
```bash
Rscript -e "install.packages('renv')"
```
5. create a project directory and initialize renv via:
```bash
mkdir /proj ; cd /proj
Rscript -e "renv::init(bare = TRUE)"
```
6. install required R libraries. NB: these will vary depending on the model (see each model's `README.md` for the actual list). For example:
```bash
Rscript -e "renv::install(c('lubridate', 'readr', 'remotes'))"
Rscript -e "renv::install('arrow', repos = c('https://apache.r-universe.dev', 'https://cran.r-project.org'))"
Rscript -e "renv::install('arrow')"
Rscript -e "renv::install('reichlab/zoltr')"
Rscript -e "renv::install('hubverse-org/hubData')"
Rscript -e "renv::install('hubverse-org/hubVis')"
Rscript -e "renv::install('hubverse-org/hubData@*release')"
Rscript -e "renv::install('hubverse-org/hubVis@*release')"
```
7. create `renv.lock` from within the R interpreter (this fails in bash) via:
```R
renv::settings$snapshot.type('all') ; renv::snapshot()
```
- create `renv.lock` from within the R interpreter (this fails in bash) via `renv::settings$snapshot.type('all') ; renv::snapshot()`
- copy the new `/proj/renv.lock` file out from the container
8. copy the new `/proj/renv.lock` file out from the container
16 changes: 8 additions & 8 deletions covid_ar6_pooled/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ This should result in a model output file and pdfs with plots under `covid_ar6_p

# requirements.txt renv and details

`requirements.txt` and `renv.lock` were generated according to [README.md](..%2FREADME.md). For `renv.lock`, we installed these specific libraries:
`requirements.txt` and `renv.lock` were generated according to [README.md](../README.md). For `renv.lock`, we installed these specific libraries:

```bash
Rscript -e "renv::install(c('lubridate', 'readr', 'dplyr'))"
Rscript -e "renv::install('arrow', repos = c('https://apache.r-universe.dev', 'https://cran.r-project.org'))"
Rscript -e "renv::install('git::https://github.com/reichlab/zoltr')"
Rscript -e "renv::install('git::https://github.com/hubverse-org/hubData')"
Rscript -e "renv::install('git::https://github.com/hubverse-org/hubVis')"
Rscript -e "renv::install('git::https://github.com/hubverse-org/hubEnsembles')"
Rscript -e "renv::install('git::https://github.com/reichlab/covidData')"
Rscript -e "renv::install('git::https://github.com/reichlab/idforecastutils')"
Rscript -e "renv::install('arrow')"
Rscript -e "renv::install('reichlab/zoltr')"
Rscript -e "renv::install('hubverse-org/hubData@*release')"
Rscript -e "renv::install('hubverse-org/hubVis@*release')"
Rscript -e "renv::install('hubverse-org/hubEnsembles@*release')"
Rscript -e "renv::install('reichlab/covidData')"
Rscript -e "renv::install('reichlab/idforecastutils')"
```
Loading