2
votes

I have a LaTeX document that is split to multiple .tex files.

I'm using R markdown to generate figures and tables.

Is it possible to generate .tex file from .Rmd without preamble, so that I will be able to just use output in my document? Currently, I need to manually copy part of the output to my .tex file

2

2 Answers

3
votes

Let's suppose your child document is named child.Rmd and has the following contents.

```{r pressure, echo=FALSE, dev='pdf'}
plot(pressure)
```

Run

knitr::knit("child.Rmd")

and you get figure/pressure-1.pdf and child.md. Then run

rmarkdown::pandoc_convert("child.md", to = "latex", output = "child.tex")

Resulting child.tex file only contains \begin{figure} ~~ \end{figure} block inside. I hope this is the desired result.

If you don't have a strong reason to use RMarkdown, I'd recommend R Sweave; knitr supports child documents

UPDATE You didn't have to remove YAML header from your Rmd file; the above knitr::knit and rmarkdown::pandoc_convert combination ignores the YAML header. Take a look at this gist. Run run_this.R script and child.Rmd will be converted to child.tex. You can of course render this Rmd file to html normally.

1
votes

You should be able to do this by creating a template containing just as much as you want. Instructions for templates are here: http://rmarkdown.rstudio.com/developer_document_templates.html

You could also look at bookdown, which by design is for documents with many chapters.