r - How do I generate text output using knit_child? -
running following fragment using knitr:
```{r results='asis'} df=data.frame(x=c('a','b'),y=1:2) (n in c('a','b')){ text='- inlined `r df[df["x"]==n,]["y"]`' cat(paste0(knit_child(text=text,quiet=true),'\n')) } ``` i output:
y 1 1
- inlined 1 y 2 2
- inlined 2
how correct desired output:
- inlined 1
- inlined 2
spotted it... double brackets cell value... doh!
```{r results='asis'} df=data.frame(x=c('a','b'),y=1:2) (n in c('a','b')){ text='- inlined `r df[df["x"]==n,][["y"]]`' cat(paste0(knit_child(text=text,quiet=true),'\n')) } ```
Comments
Post a Comment