rquarto

How to combine params and inline code in Quarto


In Quarto we can use R inline code and parameters from the YAML. I would like to combine them. Here is a reproducible example to combine inline code and parameters from the YAML:

---
title: "Params in inline code"
format: html
params:
  alpha: 2
---
       
This value is `{r} params$alpha`

Output:

enter image description here

Apparently this doesn't work. The parameters value doesn't show in the inline code of the document. The parameters does work in a code chunk, but I would like to use this in a inline code to keep the document clean. So I was wondering if anyone knows how to combine parameters and inline code like above in a Quarto document?


Solution

  • For params to work you need to explicitly set the engine to knitr like this

    ---
    title: "Untitled"
    format: html
    params:
      alpha: 2
    engine: knitr
    ---
    
    ## Params inline code 
    
    This values is `r params$alpha` 
    
    
    

    using params with inline code chunks