Skip to content

Commit

Permalink
chore: remove the function in favor of the new feature of knitr 1.44
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Sep 11, 2023
1 parent 424f925 commit ea41dfd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ BugReports: https://github.com/eitsupi/prqlr/issues
Depends:
R (>= 4.2)
Suggests:
knitr (>= 1.38),
knitr (>= 1.43.17),
rmarkdown,
DBI,
glue,
Expand Down
17 changes: 4 additions & 13 deletions R/knitr-engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ eng_prql <- function(options) {
return(knitr::engine_output(options, prql_code, ""))
}

if (.get_engine_opt(options, "use_glue", FALSE)) {
if (options$engine.opts[["use_glue"]] %||% FALSE) {
prql_code <- glue::glue(prql_code, .open = "{{", .close = "}}", .envir = knitr::knit_global())
}

target <- .get_engine_opt(options, "target", getOption("prqlr.target"))
signature_comment <- .get_engine_opt(options, "signature_comment", getOption("prqlr.signature_comment", TRUE))
target <- options$engine.opts[["target"]] %||% getOption("prqlr.target")
signature_comment <- options$engine.opts[["signature_comment"]] %||% getOption("prqlr.signature_comment", TRUE)

sql_code <- prql_code |>
prql_compile(target = target, format = TRUE, signature_comment = signature_comment)
Expand All @@ -33,7 +33,7 @@ eng_prql <- function(options) {
if (is.null(options$connection)) {
options$comment <- ""
options$results <- "asis"
info_string <- .get_engine_opt(options, "info_string", "sql")
info_string <- options$engine.opts[["info_string"]] %||% "sql"

out <- paste0(
"```", info_string, "\n",
Expand All @@ -49,12 +49,3 @@ eng_prql <- function(options) {
knitr::knit_engines$get("sql")(options) |>
sub(sql_code, prql_code, x = _, fixed = TRUE)
}

#' Get knitr engine options value or default value
#' @param options a list, knitr options.
#' @param opt_name the name of target engine option.
#' @param default the default value of the engine option.
#' @noRd
.get_engine_opt <- function(options, opt_name, default = NULL) {
options$`engine-opts`[[opt_name]] %||% options$engine.opts[[opt_name]] %||% default
}

0 comments on commit ea41dfd

Please sign in to comment.