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

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

问题描述

我只是发现 Sweave R .我看过 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 文件,然后对其进行编织以生成 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.

非常感谢...

推荐答案

以下是最适合我的方法:

Here is what works very well for me:

我有一个主文件("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中,我做\ begin {document}之后的第一件事是

In master.Rnw, the first thing after \begin{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.

希望这会有所帮助,雷纳(Rainer)

Hope this helps, Rainer

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

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