I'm using targets to render a Quarto report, which contains some eval chunk options that are based on variables created during the pipeline execution. During the execution, I started getting some errors that the variable was not found. Initially I though it was a problem with targets and started a discussion (inconsistency when using target object as input to quarto chunk options · Discussion #137 · ropensci/tarchetypes · GitHub). But on further exploration, it looks like it's a problem when issuing knitr::knit( tangle = TRUE).
If I issue knitr::knit('report_eval_test.qmd', tangle = TRUE) I get:
processing file: report_eval_test.qmd
|...................................................... | 67%
Error in eval(x, envir = envir) : object 'choice' not found
|.................................................................................| 100%
Error in eval(x, envir = envir) : object 'choice' not found
output file: report_eval_test.R
Am I doing something wrong? It's important to notice that rendering this document in RStudio (render button) works just fine.
I just updated knitr to v1.42 and the issue remains
> sessionInfo()
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
locale:
[1] LC_CTYPE=pt_BR.UTF-8 LC_NUMERIC=C LC_TIME=pt_BR.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=pt_BR.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=pt_BR.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=pt_BR.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.42
loaded via a namespace (and not attached):
[1] compiler_4.2.2 tools_4.2.2 yaml_2.3.7 xfun_0.36
I've noticed similar issues with quarto chunks not recognizing what should, to my way of thinking, should be in .Global. My workaround was to put everything in the setup chunk to create objects that could be called in later chunks. Been a while so I'm sure neither that this still works or is necessary.
Thanks. I see that the target dev has participated on that github issue you mentioned (knitr::purl). So it looks like I've stumbled on some know issues.
I can get around this by including a call to the variable in the chunk tar_read(variable) instead.
But what caught my attention is that it's inconsistent with the #| echo: chunk options, that works with variables.