Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow rmarkdown engine #43

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# sasr 0.1.2.9006

* Add a basic SAS engine for knitr.

# sasr 0.1.2

* First CRAN version of the package.
Expand Down
17 changes: 17 additions & 0 deletions R/sas_engine.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#' SAS engine function
#' @param options See knitr documentation on engines.
sas_engine <- function(options) {
if (options$eval) {
ret <- sasr::run_sas(paste0(options$code, collapse = "\n"), results = "HTML")
if (identical(ret$LST, "")) {
stop(ret$LOG)
} else {
output <- ret$LST
output <- gsub("<!DOCTYPE html>", "", output)
}
} else {
output <- NULL
}
options$results <- "asis"
engine_output(options, code = options$code, out = output)
}
3 changes: 3 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ saspy <- NULL
.onLoad <- function(libname, pkgname) {
options("sascfg" = "sascfg_personal.py")
saspy <<- import("saspy", delay_load = TRUE)
if (require("knitr", quietly = TRUE)) {
knitr::knit_engines$set(sas = sas_engine)
}
}
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Sabanes
Viya
funder
hostname
knitr
onLoad
reticulate
sas
Expand Down
32 changes: 32 additions & 0 deletions inst/example.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: "My R Markdown Document"
output: html_document
---

# Enable SASR

```{r}
library(sasr)
```

# Execute SAS

```{sas}
data example1;
input x y $ z;
cards;
6 A 60
6 A 70
2 A 100
2 B 10
3 B 67
2 C 81
3 C 63
5 C 55
;
run;

proc freq data = example1;
tables y;
run;
```
14 changes: 14 additions & 0 deletions man/sas_engine.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/sasr-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions tests/testthat/_snaps/rmarkdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# rmarkdown engine works

Code
rmarkdown::render(system.file("example.Rmd", package = "sasr"), quiet = TRUE)
Output
submit the following code:
data example1;
input x y $ z;
cards;
6 A 60
6 A 70
2 A 100
2 B 10
3 B 67
2 C 81
3 C 63
5 C 55
;
run;

proc freq data = example1;
tables y;
run;
format of result is HTML

7 changes: 7 additions & 0 deletions tests/testthat/test-rmarkdown.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# knitr engin ----
test_that("rmarkdown engine works", {
.sasr_env$.sas_session <- dummy_session
expect_snapshot(
rmarkdown::render(system.file("example.Rmd", package = "sasr"), quiet = TRUE)
)
})
Loading