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

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -