You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes it's easier to construct the path to a file in code, for example: model_path = here::here("my-code-file.stan")
in a quarto document.
Is it possible to have the include argument of a chunk evaluated?
```{.stan include=model_path}
```
doesn't appear to evaluate the variable model_path correctly. Is there a syntax option to have this variable get evaluated to return the file path, and then have the path parsed correctly as normal?
If anyone was curious, you can get this to work with the following syntax:
```{.stan include=`r model_path`}
```
noting, that as mentioned in #5, whitespace is meaningful. Quarto's syntax highlighting doesn't like this, but it seems to work correctly for me (and the resulting code is highlighted correctly in the output).
Perhaps a similar example could be included in the README? To me, this feature is extremely useful.
is raw markdown, and will be processed in Lua directly through Pandoc. So if you have a variable with the path you want to include, you need usually to come up with similar logic as any of the output you can produce with R though knitr.
This means have R code generate the raw mardkown for you - like table function do for R dataframes, or knitr do for plots, or HTML widgets producing raw HTML.
Activity
wzbillings commentedon Mar 18, 2024
If anyone was curious, you can get this to work with the following syntax:
noting, that as mentioned in #5, whitespace is meaningful. Quarto's syntax highlighting doesn't like this, but it seems to work correctly for me (and the resulting code is highlighted correctly in the output).
Perhaps a similar example could be included in the README? To me, this feature is extremely useful.
cderv commentedon Mar 20, 2024
To clarify, the syntax
is raw markdown, and will be processed in Lua directly through Pandoc. So if you have a variable with the path you want to include, you need usually to come up with similar logic as any of the output you can produce with R though knitr.
This means have R code generate the raw mardkown for you - like table function do for R dataframes, or knitr do for plots, or HTML widgets producing raw HTML.
So you could have a wrapper like this
But indeed knitr inline R code works ok in this case too.