```{r setup, include=FALSE}
# Create example data for documentation purposes
my_data <- data.frame(x = 1:3, y = letters[1:3])
knitr::opts_chunk$set(eval = FALSE)
knitr::opts_template$set(slc = list(eval = FALSE))
knitr::opts_hooks$set(engine = function(options) {
if (options$engine == 'slc') {
options$eval <- FALSE
}
options
})
```Chunk Options for SLC Code Blocks
The slcr package supports several chunk options for SLC
code blocks in Quarto documents:
input_data
Specifies an R data frame to be made available in the SLC environment:
Output:
The SLC System
Obs x y
1 1 a
2 2 b
3 3 c
NOTE: There were 3 observations read from the data set WORK.MY_DATA.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
- The data frame must exist in your R environment
- Specify the name without quotes
- The data will be available using the same name in SLC
output_data
Captures SLC output data into an R data frame:
``` slc
data want;
input column1-column3;
datalines;
1 2 3
4 5 6
run;
```
Output:
NOTE: The data set WORK.WANT has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
After which want is available as dataframe in R:
```{r eval=FALSE}
# The 'want' dataset is now available in R
str(want)
# 'data.frame': 2 obs. of 3 variables:
# $ column1: num 1 4
# $ column2: num 2 5
# $ column3: num 3 6
head(want)
# column1 column2 column3
# 1 1 2 3
# 2 4 5 6
```Please note that the output_data name needs to be escaped with double quotes.
Standard Chunk Options
SLC chunks also support standard Quarto chunk options:
```{slc echo=TRUE, eval=TRUE, include=TRUE}
proc means data=sashelp.class;
var age height weight;
run;
```Output:
The SLC System
The MEANS Procedure
Variable N Mean Std Dev Minimum Maximum
-------------------------------------------------------------------------
Age 19 13.3157895 1.4926722 11.0000000 16.0000000
Height 19 62.3368421 5.1270752 51.3000000 72.0000000
Weight 19 100.0263158 22.7739335 50.5000000 150.0000000
-------------------------------------------------------------------------
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
Available standard chunk options:
- echo: Whether to show the code (default: TRUE)
- eval: Whether to evaluate the code (default: TRUE)
- include: Whether to include the chunk in output (default: TRUE)
Combining Options
You can combine multiple chunk options for more complex workflows:
```{slc input_data=mtcars, output_data="car_summary", echo=TRUE}
proc means data=mtcars noprint;
var mpg hp;
output out=car_summary mean=avg_mpg avg_hp;
run;
```Output:
NOTE: There were 32 observations read from the data set WORK.MTCARS.
NOTE: The data set WORK.CAR_SUMMARY has 1 observations and 4 variables.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
This example: - Takes the mtcars R dataframe as input -
Calculates summary statistics - Captures the results in the
car_summary R dataframe - Shows both the code and
output