I'm not sure if this is truly a bug or not, and not sure where to submit it if it is. But today, I was working in a Quarto document that was mostly words, and then I decided to add a little arithmetic as an inline expression. I added something like {r} 2+2 into a sentence, and rendered the document. Instead of the expected 4, I saw {r} 2+2 in my document.
After some tinkering, I figured out that if you have a normal code chunk in the document, it will recognize the inline expression, but if you don't have a normal code chunk it won't. I tested with an equivalent .rmd document and it recognized the inline expression whether or not there was a normal code chunk in the document.
I am not positive but my impression is that you must do the calculations or whatever in a regular {r} section and then call it into an in-line expression.
No, you should be able to do arbitrary calculations inline. The recommendation is to keep the code simple (like I'm doing in my examples) but that's just because it's hard to debug.
This will have 4 in the rendered document
---
format: html
---
```{r}
x <- 10
```
Here is a sentence with inline code `{r} 2+2`.
But this will just have {r} 2+2 in the rendered document
---
format: html
---
Here is a sentence with inline code `{r} 2+2`.
@AmeliaMN In Quarto the engine will be automatically binded only on code cell content.
So if the document has a chunk with R language, then engine: knitr is used.
But if it only has an inline syntax - this will be engine: markdown by default.
You need to set engine: knitr in your second example and you'll see 4 evaluated.