SASmarkdown (version 0.4.3)

sas_collectcode: Create a knitr chunk hook for accumlating code.

Description

This wrapper function calls knitr::knit_hooks$set() to define a chunk hook. When the chunk hook is later invoked, this writes the contents of the current chunk to the end of a SAS autoexec.sas file.

This may be used with any of the SAS language engines: "sas", "sashtml", "saslog", or "sashtmllog".

Usage

sas_collectcode()

Arguments

Value

There are no return values, chunk hook creation is a side effect here.

Author

Doug Hemken

Details

This function is automatically invoked when the SASmarkdown library is attached. Normally a user will not need to call this function, instead using collectcode=TRUE as a chunk option - see the example below.

When knitr calls SAS, each code chunk is processed as a separate SAS batch job. Where code in one chunk depends upon the results from a prevous chunk, code needs to be repeated and re-evaluated.

This function creates a knitr chunk hook that signals when one chunk's code should be saved for re-use later. The code ends up in a temporary SAS autoexec.sas file.

See Also

SASmarkdown-package

Examples

Run this code
sas_collectcode()

if (FALSE) {
indoc <- '
---
title: "Basic SASmarkdown Doc"
author: "Doug Hemken"
output: html_document
---
# In a first code chunk, set up with
```{r}
require(SASmarkdown)

sasexe <- "C:/Program Files/SASHome/SASFoundation/9.4/sas.exe"
sasopts <- "-nosplash -ls 75"
```
# Then mark SAS code chunks with collectcode=TRUE
```{r, engine="sas", engine.path=sasexe, engine.opts=sasopts, collectcode=TRUE}
data class;
    set sashelp.class;
    keep age;
    run;
```

# A later chunk that depends on the first.
```{r, engine="sas", engine.path=sasexe, engine.opts=sasopts}
proc means data=class; /* not SASHELP.class */
run;
```
'
knitr::knit(text=indoc, output="test.md")
rmarkdown::render("test.md")
}

Run the code above in your browser using DataLab