Skip to contents

Provides support for executing SLC code blocks in Quarto documents. This function is automatically called by knitr when processing SLC code chunks.

Usage

slc_engine(options)

Arguments

options

A list of chunk options from knitr, including:

code

Character vector containing the SLC code to execute

input_data

Name(s) of R data.frame(s) to make available in SLC. Can be a single name or comma-separated names (optional)

output_data

Name(s) for capturing SLC output data into R. Can be a single name or comma-separated names (optional)

new_session

Whether to start a fresh SLC process for this chunk (default: FALSE). Set to TRUE for an isolated session that does not share state with other chunks.

show_listing

Whether to include SAS listing (LST) output below the log (default: TRUE)

output_files

Override: comma-separated paths to embed as figures. Usually not needed — figures are auto-discovered via log parsing and the &slcr_gpath temp directory.

fig-cap

Caption(s) for auto-discovered or output_files figures. A single string is applied to all figures; a vector/list assigns one caption per figure.

eval

Whether to evaluate the code (default: TRUE)

echo

Whether to show the code (default: TRUE)

include

Whether to include output (default: TRUE)

Value

A knitr engine output object containing the code and results, followed by any figure markdown.

Details

This function handles the execution of SLC code within Quarto documents by:

  • Initializing SLC connection if needed (shared by default, or fresh if new_session = TRUE)

  • Exposing &slcr_gpath — a per-chunk temp directory — as a SAS macro variable, so user code can write figures to a known location

  • Executing the SLC code

  • Capturing output, log, and listing

  • Auto-discovering figures via two complementary mechanisms: (1) parsing NOTE: Successfully written image <path> from the SAS log, (2) scanning &slcr_gpath for new image files

  • Transferring output data from SLC to R if specified

ODS GRAPHICS figure capture

Two auto-discovery mechanisms work together — no output_files needed in most cases:

  1. Log parsing: after each chunk the engine scans the SAS log for NOTE: Successfully written image ... lines. This captures figures regardless of where ODS writes them.

  2. slcr_gpath scan: figures written to &slcr_gpath (a per-chunk temp directory) are also collected. Use with ods html gpath="&slcr_gpath" for explicit placement.

Multiple datasets

Multiple datasets can be specified using comma-separated names:

  • input_data="df1,df2,df3" - transfers multiple R data.frames to SLC

  • output_data="result1,result2" - captures multiple datasets from SLC to R

  • output_files="a.png,b.png" - embeds additional files not auto-discovered

Global Environment Assignment

When output_data is specified, this function intentionally assigns the resulting dataset(s) to the global environment using assign(..., envir = knitr::knit_global()).