开发 Sweave 文档的建议 [英] Recommendations for developing Sweave documents
问题描述
我希望简化我的 Sweave 文档创建,我想听听关于人们当前的设置.我觉得圣杯是这样的:
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:
- 编辑一半的 Rnw 代码屏幕
- 单键绑定编译Sweave 文档并运行 pdflatex
- 查看PDF在屏幕的另一半;一次编译后,PDF 会刷新并以您正在编辑的文档部分为中心
- 如果编译有错误,将 PDF 替换为编译结果(例如 Latex 错误或 Sweave 错误)
我猜测/希望该解决方案是 Emacs/ESS 的一部分,并结合了 Emacs 配置文件的一些代码和/或一个不错的 Makefile.但我真的很想听听大家喜欢的创建 Sweave 和/或 Latex 文档的方式.
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.
推荐答案
我交谈过的其他一些 R 用户使用每个项目一个目录"的设置和一个简单的 Makefile.正如您所怀疑的,这与 Emacs/ESS 配合得很好.
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.
我倾向于调用一个简单的 shell 脚本 sweave
,它是我在添加R CMD Sweave"之前编写的(因为我发现重新创建或复制 Makefile 没有吸引力,YMMV).我还使用 Emacs 和自动刷新的 pdf 查看器(如 okular
或 kpdf
).Emacs23 也可以直接预览 pdf 文件,但我还没有切换到那样的工作流程.
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
这篇关于开发 Sweave 文档的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!