Skip to content

Commit

Permalink
fix: set options$engine to support quarto 1.3 (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi authored Mar 14, 2023
1 parent 1ed9ca8 commit 63bba54
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 12 deletions.
4 changes: 4 additions & 0 deletions R/knitr-engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ eng_prql <- function(options) {
# elm coincidentally provides the best syntax highlight for prql.
options$lang <- options$lang %||% "elm"

# Workaround for Quarto CLI 1.3
# https://github.com/quarto-dev/quarto-cli/pull/4735
options$engine <- "elm"

# Prints a SQL code block if there is no connection
if (is.null(options$connection)) {
options$comment <- ""
Expand Down
52 changes: 52 additions & 0 deletions tests/testthat/_snaps/knitr-engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,55 @@
```

---

Code
.knit_file("change-lang.Rmd")
Output
```prql
from mtcars
filter cyl > 6
select [cyl, mpg]
derive [mpg_int = round 0 mpg]
take 3
```
```sql
SELECT
cyl,
mpg,
ROUND(mpg, 0) AS mpg_int
FROM
mtcars
WHERE
cyl > 6
LIMIT
3
-- Generated by PRQL compiler version:0.6.1 (https://prql-lang.org)
```
```foo
from mtcars
filter cyl > 6
select [cyl, mpg]
derive [mpg_int = round 0 mpg]
take 3
```
Table: 3 records
| cyl| mpg| mpg_int|
|---:|----:|-------:|
| 8| 18.7| 19|
| 8| 14.3| 14|
| 8| 16.4| 16|

17 changes: 17 additions & 0 deletions tests/testthat/files/change-lang.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```{prql, file="simple.prql", lang="prql"}
```

```{r}
#| echo: false
#| file: set-db.R
```

```{prql}
#| connection: con
#| lang: foo
#| file: simple.prql
```

```{r, echo=FALSE}
dbDisconnect(con)
```
5 changes: 1 addition & 4 deletions tests/testthat/files/glue.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ select {{b}}

```{r}
#| echo: false
library(DBI)
con <- dbConnect(RSQLite::SQLite(), ":memory:")
dbWriteTable(con, "mtcars", mtcars)
#| file: set-db.R
```

```{prql}
Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/files/r-style-opts.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
```{r, echo=FALSE}
library(DBI)
con <- dbConnect(RSQLite::SQLite(), ":memory:")
dbWriteTable(con, "mtcars", mtcars)
```{r, echo=FALSE, file="set-db.R"}
```

```{prql engine.opts=list(target="sql.mssql", signature_comment=FALSE), file="simple.prql"}
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/files/set-db.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library(DBI)
con <- dbConnect(RSQLite::SQLite(), ":memory:")
dbWriteTable(con, "mtcars", mtcars)
5 changes: 1 addition & 4 deletions tests/testthat/files/yaml-style-opts.Rmd
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
```{r}
#| echo: false
library(DBI)
con <- dbConnect(RSQLite::SQLite(), ":memory:")
dbWriteTable(con, "mtcars", mtcars)
#| file: set-db.R
```

```{prql}
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-knitr-engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ test_that("Snapshot test of knitr-engine", {
cran = TRUE
)
expect_snapshot(.knit_file("glue.Rmd"), cran = TRUE)
expect_snapshot(.knit_file("change-lang.Rmd"), cran = TRUE)
})

0 comments on commit 63bba54

Please sign in to comment.