Title: Containerize Your 'R' Project
Version: 0.1.1
Description: Automates the process of containerizing 'R' projects. The core function of 'containr' is 'generate_dockerfile()', which 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. The package helps researchers build portable and consistent workflows so that analyses 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
RoxygenNote: 7.3.2
URL: https://github.com/erwinlares/containr, https://erwinlares.github.io/containr/
BugReports: https://github.com/erwinlares/containr/issues
Suggests: testthat (≥ 3.0.0), withr
Imports: dplyr, glue, purrr, readr, httr
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2025-09-19 18:52:24 UTC; lares
Author: Erwin Lares [aut, cre]
Maintainer: Erwin Lares <erwin.lares@wisc.edu>
Repository: CRAN
Date/Publication: 2025-09-24 08:30:02 UTC

containr: Containerize Your 'R' Project

Description

logo

Automates the process of containerizing 'R' projects. The core function of 'containr' is 'generate_dockerfile()', which 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. The package helps researchers build portable and consistent workflows so that analyses 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

See Also

Useful links:


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 NULL.

Value

A normalized file path if validation succeeds, or NULL if the input was NULL.


Generate a reproducible Dockerfile for R projects

Description

Creates a customizable Dockerfile tailored to R-based workflows, supporting multiple Rocker images (base R, tidyverse, RStudio Server, and publishing-ready configurations). The function allows inclusion of data, code, and miscellaneous files, sets up system libraries, optionally installs Quarto, and configures user access. It supports verbose output and inline comments for transparency and educational use. Designed to streamline containerization for reproducible research and deployment.

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 (TRUE or FALSE). Should generate_dockerfile() print out progress? By default, it will silently create a Dockerfile

r_version

a character string indicated a version of R, i.e., "4.3.0". By default, it will grab the version of R from the current session

data_file

a character string indicating an optional name of a data file to be copied into the container

code_file

a character string indicating an optional name of a script file to be copied into the container

misc_file

a character string indicating an optional name of miscellaneous files to be copied into the container

add_user

a character string indicating an optional name of a linux user to be created inside the container

home_dir

a character string specifying the home directory inside the container

install_quarto

logical (TRUE or FALSE). If TRUE it will include supporting packages and system libraries to support Quarto and RMarkdown.

expose_port

a character string indicating in which port will RStudio Server be accessible. It defaults to 8787

r_mode

a character string. Inspired by the images in the Rocker Project. The options are "base" for base R, "tidyverse", "rstudio" for RStudio Server, and "tidystudio" which is tidyverse plus TeX Live and some publishing-related R packages

install_syslibs

logical. If TRUE, includes system libraries commonly required by R packages and tools for source compilation.

comments

logical (TRUE or FALSE). If TRUE, the Dockerfile generated will include comments detailing what each line does. If FALSE, the Dockerfile will be bare with only commands.

output

Character. Directory path to write the Dockerfile. Defaults to tempdir().

Value

writes a Dockerfile to the specified output directory.

Examples

# Basic Usage

# Specify an image with R 4.2.0 installed

generate_dockerfile(r_version = "4.3.0")


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 "base", "rstudio", or "tidyverse". Determines which Rocker image to query. "base" maps to "rocker/r-ver".

verbose

Logical. If TRUE, prints progress messages during tag retrieval and pagination.

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. "4.4.0", "devel", or "4.4.0-cuda12.2-ubuntu22.04". Must match semantic versioning or be one of "latest", "devel".

r_mode

Character string. One of "base", "rstudio", or "tidyverse". Determines which Rocker image to query.

verbose

Logical. If TRUE, prints messages indicating whether the version was found.

Value

Logical. TRUE if the specified version tag exists for the given Rocker image; otherwise FALSE.