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

javascript - Confirm a form & display message if form is valid with JQuery -

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

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -