From 45a8a64fb223f8dd7da2bcd30614fdeb3b5ed235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liming=20Li=20=EF=BC=88=E6=9D=8E=E9=BB=8E=E6=98=8E?= =?UTF-8?q?=EF=BC=89?= Date: Mon, 29 Apr 2024 02:41:19 +0000 Subject: [PATCH 1/5] allow rmarkdown --- DESCRIPTION | 2 +- R/sas_engine.R | 17 ++++++++++++++++ R/zzz.R | 3 +++ inst/example.Rmd | 32 ++++++++++++++++++++++++++++++ man/sas_engine.Rd | 14 +++++++++++++ man/saspy.Rd | 2 +- man/sasr-package.Rd | 3 ++- tests/testthat/_snaps/rmarkdown.md | 25 +++++++++++++++++++++++ tests/testthat/test-rmarkdown.R | 7 +++++++ 9 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 R/sas_engine.R create mode 100644 inst/example.Rmd create mode 100644 man/sas_engine.Rd create mode 100644 tests/testthat/_snaps/rmarkdown.md create mode 100644 tests/testthat/test-rmarkdown.R diff --git a/DESCRIPTION b/DESCRIPTION index 93bcce2..b933d9b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,4 +41,4 @@ Encoding: UTF-8 Language: en-US LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/R/sas_engine.R b/R/sas_engine.R new file mode 100644 index 0000000..e89e460 --- /dev/null +++ b/R/sas_engine.R @@ -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("", "", output) + } + } else { + output <- NULL + } + options$results <- "asis" + engine_output(options, code = options$code, out = output) +} diff --git a/R/zzz.R b/R/zzz.R index d28e38e..706cb41 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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) + } } diff --git a/inst/example.Rmd b/inst/example.Rmd new file mode 100644 index 0000000..a380ce6 --- /dev/null +++ b/inst/example.Rmd @@ -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; +``` \ No newline at end of file diff --git a/man/sas_engine.Rd b/man/sas_engine.Rd new file mode 100644 index 0000000..86a529c --- /dev/null +++ b/man/sas_engine.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sas_engine.R +\name{sas_engine} +\alias{sas_engine} +\title{SAS engine function} +\usage{ +sas_engine(options) +} +\arguments{ +\item{options}{See knitr documentation on engines.} +} +\description{ +SAS engine function +} diff --git a/man/saspy.Rd b/man/saspy.Rd index f3aad4b..a9c3469 100644 --- a/man/saspy.Rd +++ b/man/saspy.Rd @@ -5,7 +5,7 @@ \alias{saspy} \title{saspy package} \format{ -An object of class \code{python.builtin.module} (inherits from \code{python.builtin.object}) of length 0. +An object of class \code{python.builtin.module} (inherits from \code{python.builtin.object}) of length 1. } \usage{ saspy diff --git a/man/sasr-package.Rd b/man/sasr-package.Rd index 2353494..073c988 100644 --- a/man/sasr-package.Rd +++ b/man/sasr-package.Rd @@ -2,8 +2,8 @@ % Please edit documentation in R/sasr-package.R \docType{package} \name{sasr-package} +\alias{sasr} \alias{sasr-package} -\alias{_PACKAGE} \title{\code{sasr} Package} \description{ \code{sasr} provides interface to SAS through \code{saspy} and \code{reticulate} in R. @@ -12,6 +12,7 @@ Useful links: \itemize{ \item \url{https://github.com/insightsengineering/sasr/} + \item \url{https://insightsengineering.github.io/sasr/latest-tag/} \item Report bugs at \url{https://github.com/insightsengineering/sasr/issues} } diff --git a/tests/testthat/_snaps/rmarkdown.md b/tests/testthat/_snaps/rmarkdown.md new file mode 100644 index 0000000..8d75334 --- /dev/null +++ b/tests/testthat/_snaps/rmarkdown.md @@ -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 + diff --git a/tests/testthat/test-rmarkdown.R b/tests/testthat/test-rmarkdown.R new file mode 100644 index 0000000..20c9eb9 --- /dev/null +++ b/tests/testthat/test-rmarkdown.R @@ -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) + ) +}) From cb13edda2de84d5813370c6ab56f7a1492081e35 Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 02:45:26 +0000 Subject: [PATCH 2/5] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/saspy.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/saspy.Rd b/man/saspy.Rd index a9c3469..f3aad4b 100644 --- a/man/saspy.Rd +++ b/man/saspy.Rd @@ -5,7 +5,7 @@ \alias{saspy} \title{saspy package} \format{ -An object of class \code{python.builtin.module} (inherits from \code{python.builtin.object}) of length 1. +An object of class \code{python.builtin.module} (inherits from \code{python.builtin.object}) of length 0. } \usage{ saspy From 5b7b5f69ccb312fec404b9d1942a8ddc220245f9 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 02:45:29 +0000 Subject: [PATCH 3/5] [skip style] [skip vbump] Restyle files --- inst/example.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/example.Rmd b/inst/example.Rmd index a380ce6..7f4bb70 100644 --- a/inst/example.Rmd +++ b/inst/example.Rmd @@ -29,4 +29,4 @@ run; proc freq data = example1; tables y; run; -``` \ No newline at end of file +``` From e4fcac1e61212d21ca700a1714e401ad859a238f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liming=20Li=20=EF=BC=88=E6=9D=8E=E9=BB=8E=E6=98=8E?= =?UTF-8?q?=EF=BC=89?= Date: Mon, 29 Apr 2024 02:57:01 +0000 Subject: [PATCH 4/5] update news --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index c8abde8..e8cf9e6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. From d1c0ce82d0a17377e198e948eeb06114ba011556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liming=20Li=20=EF=BC=88=E6=9D=8E=E9=BB=8E=E6=98=8E?= =?UTF-8?q?=EF=BC=89?= Date: Mon, 29 Apr 2024 03:29:03 +0000 Subject: [PATCH 5/5] update wordlist --- inst/WORDLIST | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/WORDLIST b/inst/WORDLIST index a145d97..4d75eef 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -8,6 +8,7 @@ Sabanes Viya funder hostname +knitr onLoad reticulate sas