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

comments parsed in glue_sql chunks #280

Closed
dpprdan opened this issue Nov 1, 2022 · 1 comment
Closed

comments parsed in glue_sql chunks #280

dpprdan opened this issue Nov 1, 2022 · 1 comment

Comments

@dpprdan
Copy link
Contributor

dpprdan commented Nov 1, 2022

It seems that comments in glue_sql chunks get parsed and therefore potentially throw errors.

The following is the example from https://github.com/tidyverse/glue/blob/HEAD/vignettes/engines.Rmd with the last line added as a comment.

---
title: "glue_sql chunk comments parsed"
output: github_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r prep}
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
mtcars$model <- rownames(mtcars)
DBI::dbWriteTable(con, "mtcars", mtcars)
var <- "mpg"
tbl <- "mtcars"
num <- 150
``` with

```{glue_sql test, connection = con}
SELECT `model`, `hp`, {`var`}, cyl
FROM {`tbl`}
WHERE {`tbl`}.hp > {num}
#  AND {`tbl`}.cyl < {cyls}
```

When I run all chunks (or render()) I get the following error on the last chunk

Error in eval(parse(text = text, keep.source = FALSE), envir) : 
  object 'cyls' not found

AFAICT this shouldn't happen? Or have I missed something?

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.1 (2022-06-23 ucrt)
#>  os       Windows 10 x64 (build 19044)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language en
#>  collate  German_Germany.utf8
#>  ctype    German_Germany.utf8
#>  tz       Europe/Berlin
#>  date     2022-11-01
#>  pandoc   2.19.2 @ C:/Program Files/RStudio/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  cli           3.4.1      2022-09-23 [1] CRAN (R 4.2.1)
#>  digest        0.6.30     2022-10-18 [1] CRAN (R 4.2.1)
#>  evaluate      0.17       2022-10-07 [1] RSPM
#>  fastmap       1.1.0      2021-01-25 [1] CRAN (R 4.2.0)
#>  fs            1.5.2      2021-12-08 [1] CRAN (R 4.2.0)
#>  glue        * 1.6.2.9000 2022-11-01 [1] Github (tidyverse/glue@d47d6c7)
#>  highr         0.9        2021-04-16 [1] CRAN (R 4.2.0)
#>  htmltools     0.5.3      2022-07-18 [1] CRAN (R 4.2.1)
#>  knitr         1.40       2022-08-24 [1] CRAN (R 4.2.1)
#>  lifecycle     1.0.3      2022-10-07 [1] RSPM
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.2.0)
#>  purrr         0.3.5      2022-10-06 [1] RSPM
#>  R.cache       0.16.0     2022-07-21 [1] CRAN (R 4.2.1)
#>  R.methodsS3   1.8.2      2022-06-13 [1] CRAN (R 4.2.0)
#>  R.oo          1.25.0     2022-06-12 [1] CRAN (R 4.2.0)
#>  R.utils       2.12.1     2022-10-30 [1] CRAN (R 4.2.2)
#>  reprex        2.0.2      2022-08-17 [1] CRAN (R 4.2.1)
#>  rlang         1.0.6      2022-09-24 [1] CRAN (R 4.2.1)
#>  rmarkdown   * 2.17       2022-10-07 [1] RSPM
#>  rstudioapi    0.14       2022-08-22 [1] CRAN (R 4.2.1)
#>  sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.2.0)
#>  stringi       1.7.8      2022-07-11 [1] CRAN (R 4.2.1)
#>  stringr       1.4.1      2022-08-20 [1] CRAN (R 4.2.1)
#>  styler        1.8.0      2022-10-22 [1] CRAN (R 4.2.1)
#>  withr         2.5.0      2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun          0.34       2022-10-18 [1] CRAN (R 4.2.1)
#>  yaml          2.3.6      2022-10-18 [1] CRAN (R 4.2.1)
#> 
#>  [1] C:/Users/Daniel.AK-HAMBURG/AppData/Local/R/win-library/4.2
#>  [2] C:/Program Files/R/R-4.2.1/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
@hadley
Copy link
Member

hadley commented Jan 25, 2023

Comments definitely will get parsed because glue doesn't know anything about commenting (and if it did, it would presumably expect SQL comments, not R comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants