excerptr: Excerpt Structuring Comments and Set a Table of Contents.

View source: R/excerptr.R

excerptrR Documentation

Excerpt Structuring Comments and Set a Table of Contents.

Description

Just a wrapper to the python function excerpts.excerpts. See https://pypi.org/project/excerpts/ for details.

Usage

excerptr(
  file_name,
  comment_character = "#",
  magic_character = "%",
  output_path = "",
  allow_pep8 = TRUE,
  prefix = "",
  postfix = "",
  run_pandoc = TRUE,
  compile_latex = FALSE,
  pandoc_formats = "tex"
)

Arguments

file_name

Name the file from which to excerpt.

comment_character

Should be "#" for R.

magic_character

The magic character marking the structuring comments in file_name.

output_path

Name the path where to output to.

allow_pep8

Don't bother. See excerpts.excerpts for details.

prefix

Give a prefix to use for output files.

postfix

Give a postfix to use for output files.

run_pandoc

Try to run pandoc on the output?

compile_latex

Try to compile LaTeX if pandoc has output LaTeX?

pandoc_formats

A character vector naming the output formats for pandoc.

Value

The status of excerpts.excerpts.

Examples

if (reticulate::py_available(initialize = TRUE)) {
    root <- system.file(package = "excerptr")
    test_files <- file.path(root, "excerpts", "tests", "files")
    outpath <- tempdir()
    python_source <- "some_code.py"
    f <- normalizePath(file.path(test_files, python_source))
    cat(readLines(f), sep = "\n")
    tryCatch(
             excerptr(file_name = file.path(test_files, python_source),
                      output_path = tempdir(), run_pandoc = FALSE,
                      compile_latex = FALSE,
                      pandoc_formats = c("tex", "html")),
             error = identity)
    f <- file.path(outpath, sub("\\.py$", ".md", python_source))
    if (!fritools::is_cran()) cat(readLines(f), sep = "\n")
}

excerptr documentation built on Nov. 5, 2025, 5:42 p.m.