I want to add a bit more information to my earlier post below. I am using the \input command in LaTeX and having it read another chapter of the book. That chapter contains some R code that is not being processed, although the text is coming through just fine. That chapter is given a .Rnw suffix so my input command is \input{Chapter3.Rnw}. I am wondering if that chapter requires other commands or needs to be saved under a different suffix in order for the \input command to bring in that chapter and process it along with the other chapters. I'm not receiving any error messages that indicate the problem, however when it gets to the part of the chapter that needs to have R code processed within knitr, I see this two upside down exclamation points followed by echo=FALSE followed by two upside down question marks. Then I see the code.
Thanks again,
David
In an earlier post I noted that I was running into a memory problem. This is a very big document written in LaTeX that I would like to break up into smaller documents (chapters, actually). Is that possible using R Markdown and knitr. If so, can someone please share some basic syntax of how to do that, especially how to save the separate chapters.
Have you looked into using the {bookdown} package? It's goal is to write books and technical documents and supports/encourages storing chapters in separate files.
There are other options such as using child documents, which can be inside with bookdown but is also a viable option within rmarkdown alone.
Thanks for your response. Regarding the use of child documents, my document is written in LaTeX, with knitr being used to run R code. I am using a .Rnw suffix on the files which I believe I need to typeset LaTeX and run knitr within Markdown. To designate a chunk of R code, I need to use something like
<<echo=FALSE>>=
code here
@
It seems that child documents take Rmd files. Do you know off hand what the syntax would be for Rnw files?
I think this should get you started. Let me know if you have any questions.
Actually, that link mostly shows how to add children into Rnw documents. I believe you can also include Rnw as children, and they will be knit by knitr before being injected in the main doc.
But I am receiving this error when I try to compile the document
processing file: ./testCh4.Rnw
Quitting from lines NA-185 (./testCh4.Rnw)
Error in parse_block(g[-1], g[1], params.src, markdown_mode) :
Duplicate chunk label 'set-parent', which has been used for the chunk:
set_parent('testinclude.Rnw')
Calls: knit ... process_file -> split_file -> lapply -> FUN -> parse_block
Can I have multiple calls to child in a main document.
Yes, you can definitely have multiple children within a main document.
The error you're getting indicates you have multiple code chunks labeled with the same chunk label (set-parent, in this case) in the testCh4.Rnw document. knitr throws an error in this case, so you need to make sure each chunk is uniquely labeled (or not labeled at all, knitr will automatically assign a unique label to unlabeled chunks).
It is possible to use an option to deactivate this check - this could be useful in some case, like with child document but the check is here by security I guess because chunk lable are meant to be unique for some features