Skip to contents

catchup() takes a notebook file, finds the R chunks in it, and runs them. It provides a kind of "run all chunks" functionality for working with computational R notebooks in different development environments. The chunks to be executed can be controlled via arguments.

Usage

catchup(
  doc_path,
  from_label = NULL,
  to_label = NULL,
  from_line = NULL,
  to_line = NULL,
  force_eval = FALSE,
  exec_env = NULL,
  print_results = TRUE
)

Arguments

doc_path

(Required) A string providing the path to the notebook document file. Must be a character vector of length 1.

from_label

(Optional) A string matching (in the regex sense) the value of the 'label' option of a code chunk from which point chunks should be executed. If from_label is specified, the from_line argument will be ignored. If unspecified, the function will start looking for chunks from the first line of the document. Must be a character vector of length 1.

to_label

(Optional) A string matching (in the regex sense) the value of the 'label' option of a code chunk upto and including which all chunks should be run. If to_label is specified, the to_line argument will be ignored. If unspecified, the function will look for chunks upto the final line of the document. Must be a character vector of length 1.

from_line

(Optional) A line number specifying the point in the document from which chunks should be executed. If the line number is inside of a chunk, that whole chunk will be included for evaluation. If neither from_label nor from_line is specified, the function will start looking for chunks from the first line of the document. Must be an integer or coercible to an integer.

to_line

(Optional) A line number specifying the point in the document upto which chunks should be executed. If the line number is inside of a chunk, that whole chunk will be included for evaluation. If neither to_label nor to_line is specified, the function will look for chunks up to the final line of the document. Must be an integer or coercible to an integer.

force_eval

Logical (default FALSE). If TRUE, chunks will be run even if the eval chunk option is set to "false".

exec_env

(Optional) An environment object specifying the environment in which the R expressions in the document should be run. Defaults to the frame from which the function is called, which is usually the global environment.

print_results

Logical (default TRUE). Whether to echo the evaluated expressions in the console and print a summary of what was done.

Value

The results of evaluating the expressions from the code chunks in the specified environment.

See also

source(), which is how the code inside the notebook chunks is ultimately evaluated via this function.

Examples

if (FALSE) { # \dontrun{
notebook_path <- testthat::test_path("test_data", "quarto_test.qmd")
catchup(notebook_path, print_results = FALSE)
# Variables from the notebook now exist in the environment
i_should_exist == 5

# Only run up to a certain point in the notebook
catchup(notebook_path, to_line = 30, print_results = FALSE)
print(i_should_exist)

# Force all R chunks to be evaluated
catchup(notebook_path, force_eval = TRUE, print_results = FALSE)
print(i_should_not_exist)
} # }