How to add code from an R variable into a Quarto Code Block

251 views Asked by At

I have some code stored as a character. I would like to dynamically add this code to a Quarto Code Block (Not a Code Chunk or executable Code Cell). I know I can add code into an executable code cell stored in an r variable, say, MyCode with the following lines of code:


```{r}
MyCode<-"2+3"
```

```{r}
#| eval: true
#| code: MyCode
#| echo: true

```


But is it possible to do this with a code block, and if so how? I tried the following, but this did not seem to work:


```{r}
MyCode<-"2+3"
```

```{.r}
#| eval: true
#| code: !expr MyCode
#| echo: true

```


0

There are 0 answers