Skip to contents

This function:

  1. Collects R, Rmd, or qmd scripts from dir_scripts, or uses a supplied character vector.

  2. Optionally clears dir_output and dir_docs.

  3. Sources or renders each script, skipping .qmd scripts if a Quarto project is detected.

  4. By default, copies generated .html, .pdf, or .docx files to dir_docs.

  5. By default, renders the entire Quarto project if _quarto.yml is found.

Usage

projr_run(
  scripts = NULL,
  skip_quarto_project = FALSE,
  clear_output_and_docs = FALSE,
  copy_docs = TRUE,
  dir_scripts = NULL,
  dir_output = NULL,
  dir_docs = NULL,
  dir_exec = NULL
)

Arguments

scripts

Character vector of script filenames to execute in dir_scripts, e.g. c("my_script.R", "my_doc.Rmd"). If NULL, all .R, .Rmd/.rmd, and .qmd files in dir_scripts are used.

skip_quarto_project

Logical. If TRUE, does not render the Quarto project, even if _quarto.yml is found.

clear_output_and_docs

Logical. If TRUE, clears out dir_output and dir_docs before running.

copy_docs

Logical. If TRUE, copies generated output files (.html, .pdf, .docx) into dir_docs. Does not apply to Quarto projects.

dir_scripts

Directory where scripts reside. Defaults to the working directory if NULL.

dir_output

Directory to clear if clear_output_and_docs = TRUE. Defaults to "_output" if NULL.

dir_docs

Directory in which to look for scripts. Defaults to "docs" if NULL.

dir_exec

Directory in which to execute scripts. Defaults to NULL. For R scripts, this is the working directory. For .Rmd and .qmd scripts, this is the directory containing the script. For Quarto projects, this is the working directory.

Value

Invisibly returns TRUE when complete.

Details

To avoid accidental deletion of outputs, clear_output_and_docs is by default FALSE. However, for a clean run, it is recommended to set clear_output_and_docs to TRUE.

Examples

if (FALSE) { # \dontrun{
# Run all scripts in "scripts", remove old docs/outputs, and copy
# newly generated docs to "docs"
projr_run(
  skip_quarto_project = TRUE,
  clear_output_and_docs = TRUE,
  copy_docs = TRUE
)
} # }