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

Caching sql chunks throwing error when output.var not used #1842

Open
3 tasks done
mfherman opened this issue May 1, 2020 · 1 comment
Open
3 tasks done

Caching sql chunks throwing error when output.var not used #1842

mfherman opened this issue May 1, 2020 · 1 comment
Assignees
Labels
bug

Comments

@mfherman
Copy link

@mfherman mfherman commented May 1, 2020

I'm having trouble knitting an Rmd when I set cache=TRUE for sql code chunks.

There is some discussion of a related error #1544 and rstudio/rmarkdown#914, but those examples seem to be when output.var is set in the sql chunk and the bug was fixed a couple years ago.

The following Rmd will knit the first time, but the second time when it tries to read from the cache, I get this error:

Quitting from lines 12-13 (test-sql-cache-rmd.Rmd) 
Error in fun(environment()) : invalid first argument
Calls: <Anonymous> ... call_block -> <Anonymous> -> lazyLoad -> lazyLoadDBexec -> fun
Execution halted

When cache=FALSE, the error goes away.

---
title: "sql chunk"
output: html_document
---

```{r setup, include=FALSE}
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
knitr::opts_chunk$set(echo = TRUE, connection = "con")
```

```{sql select_1, cache=TRUE}
SELECT 1
```

This issue was previously posed on RStudio Community.

> xfun::session_info("knitr")
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134), RStudio 1.3.878

Locale:
  LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
  LC_NUMERIC=C                           LC_TIME=English_United States.1252    

Package version:
  evaluate_0.14   glue_1.4.0      graphics_3.6.1  grDevices_3.6.1 highr_0.8       knitr_1.28.5    magrittr_1.5    markdown_1.1    methods_3.6.1  
  mime_0.9        stats_3.6.1     stringi_1.4.6   stringr_1.4.0   tools_3.6.1     utils_3.6.1     xfun_0.13       yaml_2.2.1     

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@solarchemist
Copy link

@solarchemist solarchemist commented Jul 17, 2020

Wow, this was a tricky bug.

I think I can add to it. This behaviour is present even with eval=FALSE. I had some chunks demoing SQL queries on my blog (using SQL chunks mostly for the sake of pretty code highlighting), and every blogdown run except the first would fail with:

Error in fun(environment()) : invalid first argument
Calls: local ... call_block -> <Anonymous> -> lazyLoad -> lazyLoadDBexec -> fun
Execution halted
Error in render_page(f) : 
  Failed to render 'content/post/2018-07-24-self-hosted-git-server/2018-07-24-gitea.Rmd'

When it failed, I would change it to a generic code chunk, and then it would run ok once before failing again the subsequent run. Anyway, thanks for explaining this weird behaviour!

This was my chunk options and code:

```{r global_options, echo=FALSE, results='hide', message=FALSE}
opts_chunk$set(
   eval    = TRUE,
   cache   = TRUE,
   message = FALSE,
   warning = FALSE)
```

```{sql eval=FALSE}
GRANT ALL ON gitea.* TO 'gitea'@'localhost';
FLUSH PRIVILEGES;
```
> xfun::session_info("knitr")
R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS, RStudio 1.3.959

Locale:
  LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8       
  LC_COLLATE=en_GB.UTF-8     LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
  LC_PAPER=en_GB.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
  LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

Package version:
  evaluate_0.14   glue_1.4.1      graphics_3.6.2  grDevices_3.6.2 highr_0.8      
  knitr_1.28      magrittr_1.5    markdown_1.1    methods_3.6.2   mime_0.9       
  stats_3.6.2     stringi_1.4.6   stringr_1.4.0   tools_3.6.2     utils_3.6.2    
  xfun_0.15       yaml_2.2.1

@cderv cderv added the bug label Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug
Projects
None yet
Development

No branches or pull requests

3 participants