From 6d365007ad3e34824565e22361241a9b1af0f2b7 Mon Sep 17 00:00:00 2001 From: Thomas Schaffter Date: Wed, 19 May 2021 14:04:27 -0700 Subject: [PATCH] Specify notebook to render via CLI args (#50) --- README.md | 5 ++--- root/render.R | 10 +++++++--- root/usr/local/bin/render | 4 +++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 75ff36e..69a7b2c 100644 --- a/README.md +++ b/README.md @@ -152,9 +152,8 @@ HTML notebook that will be saved to the same directory with the extension docker run --rm \ --env-file .env \ -v $(pwd)/notebooks:/data \ - -e RENDER_INPUT="/data/examples/notebook.Rmd" \ - tschaffter/rstudio \ - render + tschaffter/rstudio:4.0.5 \ + render /data/examples/notebook.Rmd ``` ## Versioning diff --git a/root/render.R b/root/render.R index 2982992..89a9f0d 100644 --- a/root/render.R +++ b/root/render.R @@ -1,10 +1,14 @@ -# Renders a notebook in HTML or PDF format using args specified as environment -# variables. +# Render an Rmd notebook to HTML or PDF. +# +# TODO: Use a library for managing command-line options. -input = Sys.getenv("RENDER_INPUT", unset = NA) +# input = Sys.getenv("RENDER_INPUT", unset = NA) output_format = Sys.getenv("RENDER_OUTPUT_FORMAT", unset = "html_document") quiet = Sys.getenv("RENDER_QUIET", unset = "TRUE") +options <- commandArgs(trailingOnly = TRUE) +input <- options[1] + if (is.na(input)) { stop("The environment variable RENDER_INPUT is required") } diff --git a/root/usr/local/bin/render b/root/usr/local/bin/render index b05db99..e69884b 100755 --- a/root/usr/local/bin/render +++ b/root/usr/local/bin/render @@ -1,5 +1,7 @@ #!/bin/bash +# +# Render an Rmd notebook to HTML or PDF. set -euo pipefail -Rscript /render.R \ No newline at end of file +Rscript /render.R "$@" \ No newline at end of file