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

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -