Skip to content

Commit

Permalink
renv
Browse files Browse the repository at this point in the history
  • Loading branch information
jrosell committed Dec 29, 2023
1 parent d2bb777 commit e0a07a2
Show file tree
Hide file tree
Showing 8 changed files with 970 additions and 10 deletions.
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
FROM rocker/r2u:22.04

RUN R -e "install.packages(c('dplyr', 'purrr', 'curl', 'readr', 'stringr', 'ggplot2', 'janitor', 'targets'))"
WORKDIR /workspace

RUN mkdir /output
RUN R -e "install.packages(c('dplyr', 'purrr', 'curl', 'readr', 'stringr', 'ggplot2', 'janitor', 'targets', 'renv'))"

COPY _targets.R functions.R /
COPY _targets.R functions.R /workspace

CMD R -e "sessionInfo(); targets::tar_make();"
CMD R -e "sessionInfo(); \
list.files(); \
# options(renv.config.dependencies.limit = Inf); \
renv::snapshot(lockfile = 'output/renv.lock'); \
targets::tar_make();"
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
# playground

## Run in a local computer
## Run last R package versions in Github Actions (faster but unsafer)

Look the [.github/workflows/main.yml](.github/workflows/main.yml) file.

The output files will be uploaded as an artifact zip of the executed job.


## Run last R package versions in a local computer (faster but unsafer)

```
$ git clone https://github.com/jrosell/playground
$ cd playground
$ docker build -t my-image-name . && docker run --rm --name my_pipeline_container -v $(pwd)/output:/output/:rw my-image-name
$ docker build -t my-image-name . && docker run --rm -u $(id -u):$(id -g) --name my_pipeline_container -v $(pwd)/output:/workspace/output/:rw my-image-name
```

## Run in Github Actions

Look the [.github/workflows/main.yml](.github/workflows/main.yml) file.
## Run specific R package versions in a local computer (slower but reproducible)

Add renv.lock in your root folder and run:

```
$ docker build -f renv.Dockerfile -t my-renv-name . && docker run --rm -u $(id -u):$(id -g) --name my_renv_container -v $(pwd)/output:/workspace/output/:rw my-renv-name
```

The output files will be uploaded as an artifact zip of the executed job.
2 changes: 1 addition & 1 deletion functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ get_data <- function(){
"https://raw.githubusercontent.com/b-rodrigues/modern_R/master/datasets/unemployment/unemp_2016.csv"
)
urls |>
purrr::map(readr::read_csv) %>%
purrr::map(readr::read_csv, show_col_types = FALSE) %>%
purrr::map(clean_data) %>%
purrr::list_rbind()
}
Expand Down
21 changes: 21 additions & 0 deletions renv.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM rocker/r2u:22.04

WORKDIR /workspace

RUN R -e "install.packages(c('renv'))"
COPY renv.lock renv.lock
RUN mkdir -p renv
COPY .Rprofile .Rprofile
COPY renv/activate.R renv/activate.R
COPY renv/settings.json renv/settings.json
RUN mkdir renv/cache
ENV RENV_PATHS_CACHE renv/cache
RUN R -e "renv::restore()"

COPY _targets.R functions.R /workspace

CMD R -e "sessionInfo(); \
list.files(); \
# options(renv.config.dependencies.limit = Inf); \
renv::snapshot(lockfile = 'output/renv.lock'); \
targets::tar_make();"
Loading

0 comments on commit e0a07a2

Please sign in to comment.