| Title: | Containerize Your 'R' Project |
| Version: | 0.1.3 |
| Description: | Provides tools for containerizing 'R' projects. The core function, 'generate_dockerfile()', analyzes an 'R' project's environment and dependencies via an 'renv' lock file and generates a ready-to-use 'Dockerfile' that encapsulates the computational setup. Designed to help researchers build portable, reproducible workflows that can be reliably shared, archived, and rerun across systems. See R Core Team (2025) https://www.R-project.org/, Ushey et al. (2025) https://CRAN.R-project.org/package=renv, and Docker Inc. (2025) https://www.docker.com/. |
| License: | Apache License (≥ 2) |
| Encoding: | UTF-8 |
| Language: | en-US |
| RoxygenNote: | 7.3.2 |
| URL: | https://github.com/erwinlares/containr, https://erwinlares.github.io/containr/ |
| BugReports: | https://github.com/erwinlares/containr/issues |
| Suggests: | spelling, testthat (≥ 3.0.0), withr |
| Imports: | cli, dplyr, glue, httr, purrr, readr |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-04-26 04:45:17 UTC; lares |
| Author: | Erwin Lares |
| Maintainer: | Erwin Lares <erwin.lares@wisc.edu> |
| Repository: | CRAN |
| Date/Publication: | 2026-04-26 06:50:02 UTC |
containr: Containerize Your 'R' Project
Description
Provides tools for containerizing 'R' projects. The core function, 'generate_dockerfile()', analyzes an 'R' project's environment and dependencies via an 'renv' lock file and generates a ready-to-use 'Dockerfile' that encapsulates the computational setup. Designed to help researchers build portable, reproducible workflows that can be reliably shared, archived, and rerun across systems. See R Core Team (2025) https://www.R-project.org/, Ushey et al. (2025) https://CRAN.R-project.org/package=renv, and Docker Inc. (2025) https://www.docker.com/.
Author(s)
Maintainer: Erwin Lares erwin.lares@wisc.edu (ORCID)
See Also
Useful links:
Report bugs at https://github.com/erwinlares/containr/issues
Retrieve Docker tags for a Rocker image
Description
Queries the Docker Hub API to retrieve all available tags for a specified Rocker image.
Supports user-friendly modes: "base", "rstudio", and "tidyverse".
Returns a structured list containing the image name, tag vector, and source URL.
Usage
.get_r_ver_tags(r_mode = "base", verbose = FALSE)
Arguments
r_mode |
Character string. One of |
verbose |
Logical. If |
Value
A named list with the following elements:
- image
Character string. The full Docker image name, e.g.
"rocker/r-ver".- tags
Character vector. All available tags for the specified image, e.g.
c("latest", "devel", "4.4", "4.4.3", ...).- source
Character string. The base URL of the Docker Hub API used to retrieve the tags.
Check if a specific Rocker image tag exists
Description
Validates the format of a version string and checks whether it exists among the available tags for a specified Rocker image on Docker Hub. Supports semantic versioning, CUDA variants, and Ubuntu suffixes.
Usage
.r_ver_exists(version, r_mode = "base", verbose = FALSE)
Arguments
version |
Character string. The tag to check for existence, e.g. |
r_mode |
Character string. One of |
verbose |
Logical. If |
Value
Logical. TRUE if the specified version tag exists for the given Rocker image; otherwise FALSE.
Validate a file argument
Description
Internal helper used by generate_dockerfile() to check that
optional file arguments (e.g. data_file, code_file,
misc_file) are valid.
Usage
.validate_file_arg(arg_name, value)
Arguments
arg_name |
Character string, the name of the argument being checked (used only in error messages). |
value |
A character path to a file, or |
Value
A normalized file path if validation succeeds, or NULL
if the input was NULL.
Generate a reproducible Dockerfile for an R project
Description
generate_dockerfile() inspects an R project's dependencies via an renv
lockfile and writes a ready-to-use Dockerfile to the specified output
directory. It supports multiple Rocker base images, optional system
libraries, Quarto installation, file copying, user creation, and inline
documentation comments.
Usage
generate_dockerfile(
verbose = FALSE,
r_version = "current",
data_file = NULL,
code_file = NULL,
misc_file = NULL,
add_user = NULL,
home_dir = "/home",
install_quarto = FALSE,
expose_port = "8787",
r_mode = "base",
install_syslibs = TRUE,
comments = FALSE,
output = tempdir()
)
Arguments
verbose |
Logical. If |
r_version |
A character string specifying the R version to use, e.g.
|
data_file |
A character string. Path to an optional data file to copy
into the container under |
code_file |
A character string. Path to an optional script file (e.g.
|
misc_file |
A character string. Path to an optional miscellaneous file
(e.g. an image or shell script) to copy into the container under
|
add_user |
A character string. Name of a Linux user to create inside
the container with sudo access. Defaults to |
home_dir |
A character string. The working directory set inside the
container via |
install_quarto |
Logical. If |
expose_port |
A character string. The port to expose when |
r_mode |
A character string selecting the Rocker base image. Inspired
by the Rocker Project. One of |
install_syslibs |
Logical. If |
comments |
Logical. If |
output |
A character string. Directory path where the |
Value
Called for its side effects. Writes a Dockerfile to output.
Does not return a value.
Examples
# Generate a minimal Dockerfile using a pinned R version
generate_dockerfile(r_version = "4.4.0", output = tempdir())
# Pin a specific R version with the tidyverse image
generate_dockerfile(r_version = "4.3.0", r_mode = "tidyverse", output = tempdir())
# Include a data file and annotate the Dockerfile with comments
## Not run:
generate_dockerfile(
r_version = "4.3.0",
data_file = "data/penguins.csv",
comments = TRUE,
output = "."
)
## End(Not run)