我怎么Sweave一个多文件的项目?
-
27-09-2019 - |
题
我在写我的论文可在乳胶因为事情变得有点长对我的口味,我已经把它分成几个文件。让我们叫他们 thesis.tex
, intro.tex
, mat_n_met.tex
, rslts.tex
和 discsn.tex
.我已经联系 intro.tex
, mat_n_met.tex
, rslts.tex
和 discsn.tex
通过 thesis.tex
与 \include{intro}
(等等...).我们还创建了一个单独的文件中被称为 r_crunching.Rnw
(我跑过Sweave)拥有的一块运行R脚本用的数据分析和的大块生产pdf输出的图表,我嵌入通过 \includegraphics
(在如 rslts.tex
).仍然下?
如果我运行了一次苹果(即我重新命名 rslts.tex
要 rslts.Rnw
)没有"链接"的大块R脚本,你会得到一个 Sweave()
错误说法的参考 \Sexpr{}
并不存在。有没有一种方法,没有合并的所有文件纳入一个单一的。次苹果,呼叫 \Sexpr{}
在说 rslts.Rnw
?
其他方法如何完成,这是值得欢迎的。
解决方案
忘记的第二个,你正在处理的Sweave只是觉得胶乳问题--对于这 \include
和 \includeonly
提供解决方案。尝试用一些简单的试验的文件。
一旦你已经想通了,折Sweave回到混合和它只是工作Sweave是后'仅'一个预处理步骤,尽管是一个非常聪明的一个。
其他提示
我建议使用后他以俳句(http://www.rstudio.com/ide/).Sweave是很好的融入,IDE和它支持多文件的文件。甚至Synctex和TeX错误记录的导航工作仍然在工作时与多文件的文件。
从掌握的文件可以包括儿童使用的文件
\SweaveInput{Child.Rnw}
你可以链接,一个儿童的文件回来的主人的文件包括该指令
% !Rnw root = Master.Rnw
在儿童的文件。这种方式工作时,在一个儿童的文件和排版它,后他以俳句知道排的主文件。
详细解释后他以俳句的文档 http://www.rstudio.com/ide/docs/authoring/multiple_rnw_files
扩大德克和mjm的答案,我建议使用 \include
's和Makefile.
假如你有个硕士文件: master.tex
.在该文件中,则包括一些 .tex
和 .Rnw
的文件,即
\include chapter1
\include chapter2
\include chapter3
....
现在以下Makefile提供用于创建的 .tex
, .R
和 .pdf
文件:
.SUFFIXES: .tex .pdf .Rnw .R
MAIN = master
##List your your .Rnw includes
RNWINCLUDES = chapter1 chapter2 chapter3
TEX = $(RNWINCLUDES:=.tex)
RFILES = $(RNWINCLUDES:=.R)
RNWFILES = $(INCLUDES:=.Rnw)
all: $(MAIN).pdf
$(MAIN).pdf: $(TEX) $(MAIN).tex
R: $(RFILES)
.Rnw.R:
R CMD Stangle $<
.Rnw.tex:
R CMD Sweave $<
.tex.pdf:
pdflatex $<
bibtex $*
pdflatex $<
pdflatex $<
基本上, .SUFFIXES
提供一套规则转换成一个文件格式到另一个。例如,为转换 .Rnw
要 .R
, 我们使用的命令
`R CMD Stangle $<`
一个相当明显的答案是一个生成文件,可能使用包cachesweave,来处理相关文件正确的顺序。
我的解决方案的多文件项目Sweave(根据后他以俳句)如下:
1)创建一个主文件,说 master.Rnw
, ,你有电话给子文件 intro.Rnw
, matmet.Rnw
, 等:
\documentclass[11pt]{book}
% \usepackage{blah, blah} as you wish
\graphicspath{ {./figs/}
\begin{document}
\SweaveOpts{concordance=TRUE}
\include{intro} % a call to 'intro.Rnw'
\include{matmet} % a call to 'matmet.Rnw'
\include{results} % a call to 'results.Rnw'
\include{discuss} % a call to 'discuss.Rnw'
\end{document}
2)创造电子文件.我给这里只有第一个, intro.Rnw
.请注意,在电子文件你 请勿使用 序言部分等命令 \documentclass
或 \begin{document}
\chapter{Introduction}\label{ch:intro}
\section{This is section 01}
In section 01 we are concerned about whether \texttt{Sexpr} could possibly work. The chunk below creates a variable \em{a} which will be referred to by this command later on.
<<>>=
a <- 1+2
@
Ok, if it is working, we shall see number 3 right here: \Sexpr{a}.
3)节的修改在介绍。次苹果'的,只是去'的主人。次苹果'并编制其使用按Ctrl+Shift+K和...瞧: