I am writing a custom knitr language engine to support https://github.com/ropensci/targets/discussions/469, and I would like users to be able to write R Markdown code chunks like this:
```{tar_target analysis, pattern = map(data)}
run_analysis(data)
```
I want to avoid evaluating the pattern argument because map(data) is a DSL in tar_target() and not actual R code. But when I run the chunk, I get a "could not find function 'map'" error before control passes to the engine. Is it possible for me as the developer to call substitute() on the necessary options before knitr tries to evaluate them?
EDIT: thinking about supporting a wrapper to control special arguments to tar_target():
```{tar_target analysis, tar_args = tar_args(pattern = map(data), error = "workspace")}
run_analysis(data)
```
map(and maybe other functions) which, when invoked, return an unevaluated expression, similar to what~does? That way you wouldn’t prevent knitr evaluating the arguments but the outcome would be the same: you can still access the unevaluated version. Of course the challenge then is to expose these functions only to knitr, not to user code.tar_args()wrapper in the edit to the OP? Would that be too awkward or burdensome for the user?patternis a language object, thenknitrautomatically converts it to"NA", even inside atar_argslist. So the user might just have to quote arguments on a case-by-case basis if we use chunk options. The only other alternative I can think of is to avoid chunk options altogether and use some kind of unidiomatic custom inline YAML to specify arguments totar_target().