开发 Sweave 文档的建议

发布于 2024-08-03 17:09:08 字数 424 浏览 11 评论 0原文

我希望简化我的 Sweave 文档创建过程,并且我想了解人们当前的情况设置。我觉得圣杯是这样的:

  • 在一半上编辑 Rnw 代码 screen
  • 单键绑定编译 Sweave 文档并运行 pdflatex
  • 查看 PDF 在屏幕的另一半;一次 编译后,PDF 会刷新并以您正在编辑的文档部分为中心
  • 如果编译有错误,请将 PDF 替换为编译结果(例如 Latex 错误或 Sweave 错误)

我猜测/希望解决方案是 Emacs 的一部分/ESS 与 Emacs 配置文件和/或漂亮的 Makefile 的一些代码相结合。但我真的很想听听每个人创建 Sweave 和/或 Latex 文档的首选方式。

I'm looking to streamline my Sweave document creation, and I'd like to hear about people's current setups. I feel like the holy grail goes something like this:

  • Editing Rnw code on one half of the
    screen
  • Single keybinding compiles
    Sweave document and runs pdflatex
  • View PDF
    on the other half of the screen; once
    compiled, PDF is refreshed and centered around the portion of the document you're editing
  • If compilation has errors, replace the PDF with the results of the compilation (e.g. latex errors or Sweave errors)

I am guessing/hoping that the solution is part Emacs/ESS combined with some code for the Emacs profile and/or a nice Makefile. But I would really like to hear about everybody's preferred way of creating Sweave and/or Latex documents.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

冰之心 2024-08-10 17:09:08

我采访过的其他一些 R 用户使用“每个项目一个目录”设置和一个简单的 Makefile。正如您所怀疑的,这与 Emacs/ESS 配合得很好。

我倾向于只调用一个简单的 shell 脚本 sweave,它是我在添加“R CMD Sweave”之前编写的(因为我发现重新创建或复制 Makefile 没有吸引力,YMMV)。我还使用 Emacs 和自动刷新 pdf 查看器(如 okular 或 kpdf)。 Emacs23也可以直接预览pdf文件,但我还没有将我的工作流程切换到它。

edd@ron:~$ cat bin/sweave
#!/bin/bash -e

function errorexit () {
    echo "Error: $1"
    exit 1
}

function filetest () {
    if [ ! -f $1 ]; then
       errorexit "File $1 not found"
    fi
    return 0
}


if [ "$#" -lt 1 ]; then
    errorexit "Need to specify argument file"
fi


BASENAME=$(basename $1 .Rnw)

RNWFILE=$BASENAME.Rnw
filetest $RNWFILE
echo "library(tools); Sweave(\"$RNWFILE\")" \
      | R --no-save --no-restore --slave

LATEXFILE=$BASENAME.tex
filetest $LATEXFILE && pdflatex $LATEXFILE

A few other R users I talked to use a 'one-directory-per-project' setup, and a simple Makefile. As you suspected, that works well with Emacs/ESS.

I tend to just call a simple shell script sweave which I wrote before before 'R CMD Sweave' was added (as I find re-creating or copying the Makefile unappealing, YMMV). I also use Emacs and an auto-refreshing pdf viewer (like okular or kpdf). Emacs23 can preview pdf files directly too but I have yet to switch my work flow to that.

edd@ron:~$ cat bin/sweave
#!/bin/bash -e

function errorexit () {
    echo "Error: $1"
    exit 1
}

function filetest () {
    if [ ! -f $1 ]; then
       errorexit "File $1 not found"
    fi
    return 0
}


if [ "$#" -lt 1 ]; then
    errorexit "Need to specify argument file"
fi


BASENAME=$(basename $1 .Rnw)

RNWFILE=$BASENAME.Rnw
filetest $RNWFILE
echo "library(tools); Sweave(\"$RNWFILE\")" \
      | R --no-save --no-restore --slave

LATEXFILE=$BASENAME.tex
filetest $LATEXFILE && pdflatex $LATEXFILE
何以笙箫默 2024-08-10 17:09:08

您可以使用 Eclipse 的 StatET 插件执行您建议的所有操作。这就是我用于 Sweave 开发的方法;它很好地理解 Latex 和 R,包括语法突出显示等。

您可以在这里获取它: http:// /www.walware.de/goto/statet

Longhow Lam 写了一篇很好的指南:http://www.splusbook.com/Rintro/R_Eclipse_StatET。 pdf

http://www.statalgo.com/?p=93

You can do everything that you suggest there with the StatET plugin for Eclipse. That's what I use for Sweave development; it understands both latex and R very well, including syntax highlighting, etc.

You can get it here: http://www.walware.de/goto/statet.

Longhow Lam has written a nice guide: http://www.splusbook.com/Rintro/R_Eclipse_StatET.pdf.

http://www.statalgo.com/?p=93

往昔成烟 2024-08-10 17:09:08

我在 OS X 上使用 TeXShop 来生成所有 LaTeX 和 Sweave 报告。对我来说,新的编译管道就像将一个名为 Sweave.engine 的文件添加到 ~/Library/TeXShop/Engines/ 一样简单,其中包含以下内容:

#!/usr/bin/env Rscript
args <- commandArgs(T)

fname <- strsplit(args[1],'\\.')[[1]][2]

Sweave(paste(fname,'Rnw',sep='.'))

system(paste('pdflatex',paste(fname,'tex',sep='.')))

Sweave 现在在 TeXShop 中编译文档的可选方法。我可以通过将以下 TeX hash-bang 添加到文件顶部来将其设置为文档的默认值:

% !TEX TS-program = Sweave

点击 Cmd-T 将排版文档 - pdf 会自动弹出在单独的窗口中。 TeXShop 还结合了 SyncTeX 技术,因此 Rnw 源中的 Cmd-Click 将突出显示PDF 窗口和 PDF 窗口中的 Cmd-Click 将突出显示 Rnw 源中的相应输入。

TeXShop 仅适用于 Mac,但它是一个基于 Qt/poppler 的出色克隆,TeXworks,可用于 Linux 、Windows 和 Mac,并支持许多相同的功能——包括 TeX hash-bangs 和 SyncTeX。 TeXworks 已经达到了成熟的水平,它包含在 Windows 的 MikTeX 软件包的 2.8 版中。

I use TeXShop on OS X to produce all of my LaTeX and Sweave reports. For me, a new compilation pipeline is as simple as adding a file, called Sweave.engine to ~/Library/TeXShop/Engines/ which contains the following:

#!/usr/bin/env Rscript
args <- commandArgs(T)

fname <- strsplit(args[1],'\\.')[[1]][2]

Sweave(paste(fname,'Rnw',sep='.'))

system(paste('pdflatex',paste(fname,'tex',sep='.')))

Sweave is now a selectable method of compiling a document inside TeXShop. I can set it to be the default for a document by adding the following TeX hash-bang to the top of the file:

% !TEX TS-program = Sweave

Hitting Cmd-T will typeset the document- the pdf automatically pops up in a separate window. TeXShop also incorporates SyncTeX technology so a Cmd-Click in the Rnw source will highlight the corresponding output in the PDF window and a Cmd-Click in the PDF window will highlight the corresponding input in the Rnw source.

TeXShop is mac-only but a great Qt/poppler-based clone, TeXworks, is available for Linux, Windows and Mac and supports many of the same features-- including TeX hash-bangs and SyncTeX. TeXworks has reached a level of maturity where it is included in version 2.8 of the MikTeX package for Windows.

拒绝两难 2024-08-10 17:09:08

尝试 RStudio

我一直是 EmacsTeXShop 如之前的答案中所述。

然而,Rstudio 开始赢得我的青睐。它是一个快速改进的 R 专用 IDE。绝对值得一试。

我仍然喜欢在 Mac 版标准 R IDE 中执行某些仅限 R 的开发任务。但对于同时进行 Sweave 文档和一些相关的 R 开发,RStudio 胜出。它的工作原理几乎是零调整。我不确定原始问题后半部分与 PDF 相关的功能。

Try RStudio.

I have been a fan of Emacs and TeXShop as mentioned in previous answers.

However, Rstudio is starting to win me over. It is a rapidly-improving dedicated IDE for R. Definitely worth checking out.

I still love doing certain R-only development tasks in the standard R IDE for mac. But for Sweave documents and some associated R devel at the same time, RStudio wins. It works with virtually zero tweaking. I'm not sure about the PDF-related features in the latter half of the original question.

余生一个溪 2024-08-10 17:09:08

emacs 中的“自动插入”模式为我节省了一些时间。我已经将其设置为每次打开新的 .rnw 文件时,emacs 都会自动设置一个基本文档模板,而我所需要做的就是开始编写报告。

更新:我已经不再使用自动插入。现在我使用“template.el”方法。

One thing that has saved me some time is the 'auto-insert' mode in emacs. I have it set up so that each time I open a new .rnw file, emacs automatically sets up a basic document template and all I need to do is start writing my report.

Update: I've switched away from auto-insert. Now I use the "template.el" approach.

月光色 2024-08-10 17:09:08

我也使用“每个项目一个目录”和 Makefile 方法。我还包括在 HTML 中创建输出的命令,然后可以使用 tth 将其转换为 OOo 和 MS Word。这对我来说很重要,因为我的很多合作者都是 MS Office 用户,并且不愿意使用 PDF 输出。我从范德比尔特大学 Frank Harrell 的 twiki 中学到了很多关于如何做到这一点的知识。

就我个人而言,我使用 gvim 作为我选择的编辑器,并且从那里运行 make 非常简单,因为它来自 Emacs。

I use the "one-directory-per-project" and Makefile approach as well. I also include commands to create output in HTML, which can then be converted to OOo and MS Word, using tth. This is important for me since a lot of my collaborators are MS Office users and are resistant to using the PDF output. I learned a lot about how to do this from Frank Harrell's twiki at Vanderbilt.

Personally I use gvim as my editor of choice and running make from there is quite simple, as it is from Emacs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文