Skip to contents

Render a .textSection object as a temporary HTML report to check whether the section text and code can be rendered successfully.

Usage

testSection(x, object, view)

Arguments

x

A .textSection object, usually created with reportSection().

object

An optional camReport object created by camData(). The default is NULL.

view

A logical value (default TRUE) specifying whether the rendered temporary HTML file is opened after rendering.

Value

Invisibly returns the path to the rendered temporary HTML file.

Details

Security: Testing executes the section's text interpolation and R code with your R process's permissions. Test only sections from sources you trust; this is not a sandbox or a security check. See modules.

This function is mainly used to test custom report sections before they are added to a full camReport report. It checks whether the section text, R Markdown chunk settings, required packages, and R code can be rendered successfully.

Declared module packages are checked for availability without being attached to the R search path. Use explicit calls such as dplyr::filter() in custom module code instead of relying on the previously automatic attachment of declared packages. This requirement also applies when rendering full reports.

The object argument is only needed when the R code in the section refers to a camReport object.

Examples

tx <- reportSection(
  name = "introduction",
  title = "Introduction",
  parent = NULL,
  txt = "This is an introduction section.",
  code = {
    plot(1:10)
  }
)

# Render the section without opening a browser
test_file <- testSection(
  tx,
  view = FALSE
)

file.exists(test_file)
#> [1] TRUE

# Remove the generated HTML file
unlink(test_file)