Skip to contents

Generates a dockerfile based on an R script, analyzing its dependencies and creating a container that can run the script.

Usage

dk_from_script(
  script_file,
  base_image = "rocker/r-ver:latest",
  include_sysreqs = TRUE
)

Arguments

script_file

Path to R script

base_image

Base image to use (default: latest rocker/r-ver)

include_sysreqs

Include system requirements (default: TRUE)

Value

A dockerfile object configured to run the specified R script

Details

This function analyzes the R script to identify package dependencies by scanning for library() and require() calls. It then:

  • Creates a dockerfile with the specified base image

  • Adds necessary system requirements for the detected packages

  • Installs the required R packages

  • Copies the script to the container

  • Sets up a command to run the script

The dockerfile can be customized further after creation if needed.

See also

dk_from_session() for creating from the current session, dk_from_renv() for creating from renv.lock files, & dk_from_description() for creating from DESCRIPTION files

Other dockerfile from environment functions: dk_from_description(), dk_from_renv(), dk_from_session()

Examples

if (FALSE) { # \dontrun{
# Create a dockerfile for an R script
df <- dk_from_script("analysis.R")

# Use a specific base image
df <- dk_from_script("analysis.R", base_image = "rocker/tidyverse:4.4.0")
} # }