Use of include and input in Sweave documents

January 16, 2009
By

(This article was first published on Gregor Gorjanc, and kindly contributed to R-bloggers)

When you write a large structured document using LaTeX, it is wise to use \input{} and/or \include{} commands (see here for a nice description). However, you can not "fully" use these two commands with Sweave documents. You can use them, but when you weave the master file, the \input{} and \include{} files are not weaved! The author of Sweave instead implemented the \SweaveInput{} command. If you still want to use \input{} and/or \include{}, then you can take the following approach.

Say we have a master file file0.Rnw, which includes file1.Rnw and file2.Rnw. Then you need first to run Sweave on file1.Rnw and file2.Rnw and at the end on file0.Rnw. Warning! - there can be no interaction between files, which basically means that you can use this approach only if each file represents a complete analysis. This might be a suitable Makefile in such cases:
all: sweave # Compile the whole document
Sweave.sh --latex2pdf file0.Rnw

sweave: # Sweave individual files
Sweave.sh file1.Rnw file2.Rnw
If master file is a pure LaTeX file, you can change the all target to:
all: sweave # Compile the whole document
Sweave.sh --noweave --latex2pdf file0.tex

To leave a comment for the author, please follow the link and comment on his blog: Gregor Gorjanc.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , ,

Comments are closed.