Knit_child in Rmd file prints unwanted output

I have successfully used knit_child to create pdf files, following the code http://yihui.name/knitr/demo/child/ , but when I try to use this example in a .Rmd file:

 ```{r, results='asis', echo=FALSE, message=FALSE} out = NULL for (p in c("p1","p2","p3","p4","p5","p6","p7","p8","p9","p10")) { out = c(out, knit_child('quick_variable.Rmd')) cat(out) } ``` 

(I change the source code, work in Rmd ).

I have two problems: first:

 | | | 0% | |... | 5% ordinary text without R code | |....... | 11% label: unnamed-chunk-4 (with options) List of 1 $ echo: logi FALSE | |.......... | 16% ordinary text without R code | |.............. | 21% label: unnamed-chunk-5 (with options) List of 2 $ echo : logi FALSE $ results: chr "asis" .... (the output follows) 

Obviously, all this conclusion is undesirable. I believe this problem is related to using cat in the above code, but if I remove this, no output, no graphics will be printed. What can I do to solve this problem?

Thank you in advance

+6
source share
1 answer

You can collect the results in out and write them to the output later in the built-in R expression, for example.

 ```{r include=FALSE} out = NULL for (p in c("p1","p2","p3","p4","p5","p6","p7","p8","p9","p10")) { out = c(out, knit_child('quick_variable.Rmd')) } ``` `r paste(out, collapse='\n')` 
+6
source

Source: https://habr.com/ru/post/954284/


All Articles