Trying to knit pdf/html with appendix containing Rmd code

Using this as the last chunk:

### Appendix: Rmarkdown Code
```{r catRmd,asis=TRUE}
rmd<-read_lines("catRmd.Rmd")
cat(paste(rmd,"\n"))

Output as expected when running chunk, but knitting to either pdf or html truncates lines and prepends each with two hash marks.

See attached for details

catRmd.pdf (140.5 KB)
catRmdCode.pdf (12.3 KB)

What are you trying to do exactly ?

Do you want to use the content of catRmd.Rmd to inserted in another Rmd file ?

If that so, the way to do that is using child document feature

Given that the contents of the attached catRmdCode.pdf is copied to a file catRmd.Rmd, when catRmd.Rmd is knitted, I want the literal unknitted contents of catRmd.Rmd echoed to an appendix of the knitted document, ie either catRmd.pdf or catRmd.html.

Is there a way to do this?

I have tried

# ```{r, echo=FALSE, results='asis'}
res <- knitr::knit_child('catRmd.Rmd', 
                         options=list(echo=TRUE,eval=FALSE),
                         quiet = TRUE)
cat(res, sep = '\n')
# ```

but this appears to start knitting catRmd.Rmd and fails with a duplicate chunk label error.

Ok so I misunderstood - you want to show the content of carRmd.Rmd without evaluating it.

This is still in the doc:

The embed engine should be what you need

```{embed}
"catRmd.Rmd"
```

See the section in the book

Using embed, the lines are now not truncated. Is there any way to omit the "##" prepended to each line?

Sorry I don't follow. This should not add ##

---
title: "Demo"
output: html_document
---

See some demo file

```{embed}
dummy.Rmd
```

which dummy.Rmd being an example to show

---
title: dummy
output: html_document
---

Some demo content

```{r}
1 + 1
```

Rendering this I'll get

No ## on lines.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.