使用 Sweave 编写大型文档.可以像使用 LaTeX 一样吗? [英] Writing big documents with Sweave. Is it possible to do as with LaTeX?

查看:17
本文介绍了使用 Sweave 编写大型文档.可以像使用 LaTeX 一样吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在发现 SweaveR.我看过一些Sweave文档的例子,也开始自己写一两个.我对在 R 中进行计算并直接在 LaTeX 文档中输出结果的能力印象深刻.

I am just discovering Sweave and R. I have seen some examples of Sweave documents and have also started to write one or two on my own. I am impressed by the ability of doing computations in R and outputting results directly in a LaTeX document.

现在我正在考虑由几个页面和几个部分组成的更大的文档(就像我们通常使用 LaTeX 一样).使用 LaTeX(我使用 WinEdt),我设置了一个主文档(例如 main.tex),然后设置了其他辅助文档,例如 introduction.tex, discussion.tex 等.

Now I am thinking of bigger documents (as we usually have with LaTeX) that consist of several pages and several parts. With LaTeX (I use WinEdt), I set a main document (e.g. main.tex) and then have other subsidiary documents like introduction.tex, discussion.tex etc.

我的问题是:我们也可以使用 Sweave 来做到这一点吗?现在我正在单独使用单个 Sweave 文档 (.Rnw).我们可以像通常使用 LaTeX 那样拥有多个 Sweave 文档(一个主要的和次要的)吗?

My question is: Can we do this with Sweave as well? Now I am working with single Sweave document (.Rnw) alone. Can we have multiple Sweave documents (with one main and the secondary ones) like we normally do with LaTeX?

一种解决方法是拥有单独的 Sweave 文件,然后将它们 sweave 生成​​ R LaTeX 块,这些块可以复制到 LaTeX 文档,但整个想法似乎非常低效且耗时.

A workaround would be to have separate Sweave files and then sweave them to produce the R LaTeX chunks which can be copied to a LaTeX document but then the whole idea seems quite inefficient and time consuming.

请告知您有什么建议和解决方案.

Please do let know what suggestions and solutions that you have.

非常感谢...

推荐答案

这对我来说非常有效:

我有一个没有文本的主文件(master.Rnw"),它只用于收集最终形成文档的文件(章节、节).

I have one master file ("master.Rnw") that has no text but only serves to collect the files (chapters, sections) which form the document in the end.

然后我有一个包含 R 代码的文件,该文件在其他各种文件(func.Rnw")中重复使用.在这里,我有很多命名的块

Then I have one file with R code that is being reused in various other files ("func.Rnw"). Here, I have lot of named chunks

<<my_fun_1,eval=FALSE,echo=FALSE>>=
# code:
c <- a * b
@

在master.Rnw中,我在egin{document}之后做的第一件事就是

In master.Rnw, the first thing after egin{document} I do is

SweaveInput{func.Rnw}

从那里,我有我的命名块可用.在文件chap1.Rnw"中我现在可以拥有

and from there, I have my named chunks available. In a file "chap1.Rnw" I can now have

<<echo=FALSE>>=
a <- 10
b <- 25
<<my_fun_1>>
c
@

当然,我必须

SweaveInput{chap1.Rnw})

进入master.Rnw.

into master.Rnw.

我只需要 Sweave{master.Rnw} 然后 pdflatex 生成 master.tex 文件,无需复制/粘贴或处理多个文件.

I only have to Sweave{master.Rnw} and then pdflatex the resulting master.tex file, no copying/ pasting or processing of multiple files.

我只是在写一篇 60 多页的论文,其中包含大约 25 个表格和数字,到目前为止一切都很好.

I'm just writing a paper of 60+ pages with about 25 tables and figures and everything works perfectly well so far.

希望这会有所帮助,雷纳

Hope this helps, Rainer

这篇关于使用 Sweave 编写大型文档.可以像使用 LaTeX 一样吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆