使用非 R 代码块进行 SWeave?

发布于 2024-10-17 22:05:40 字数 336 浏览 7 评论 0原文

我经常使用 Sweave 来生成 LaTeX 文档,其中某些块是通过执行 R 代码动态生成的。这工作得很好 - 但是否也可以有以不同方式执行的代码块,例如通过在 shell 中执行代码,或通过运行 Perl 等等?能够混合起来会很有帮助,所以我可以做一些事情,比如运行一些 shell 命令来获取一些数据,运行一些 perl 命令来预处理它,然后运行 ​​R 命令来分析它。

当然,我可以使用所有 R 块并使用 system() 作为穷人的替代品,但这并不能让文档阅读起来非常愉快。

I often use Sweave to produce LaTeX documents where certain chunks are produced dynamically by executing R code. This works well - but is it also possible to have code chunks that are executed in different ways, e.g. by executing the code in the shell, or by running Perl, and so on? It would be helpful to be able to mix things up, so I could do things like run some shell commands to fetch some data, run some perl commands to pre-process it, and then run R commands to analyze it.

Of course I could use all R chunks and use system() as a poor-man's substitute, but that doesn't make for very pleasant reading in the document.

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

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

发布评论

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

评论(5

凉风有信 2024-10-24 22:05:40

新的新事物(针对多语言、多格式)文档可能是 dexy.it,例如这些 opengamma.org 的人用作后端。

dexy 背后的 Ana 也就此发表了很多演讲,因此也请查看 dexy 博客

The new new thing (for multi-language, multi-format) docs may be dexy.it which for example these guys at opengamma.org use as the backend.

Ana, who is behind dexy, is also giving a lot of talks about it so also look at the dexy blog.

月亮坠入山谷 2024-10-24 22:05:40

它与 Sweave 没有直接关系,但是 org-babel,它是 Emacs org-mode 的一部分,允许在一个文件中混合不同语言的代码块,从将一个块复制到另一个块,执行它们,并从输出生成 LaTeX 或 HTML 导出。

您可以在这里找到有关 org-mode 的更多信息:

http://www.orgmode.org/

并查看org-babel 的工作原理:

http://orgmode.org/worg/org-contrib/babel/

It's not directly related to Sweave, but org-babel, which is part of Emacs org-mode, allows to mix code chunks of different languages in one file, pass data from one chunk to another, execute them, and generate LaTeX or HTML export from the output.

You can find more informations about org-mode here :

http://www.orgmode.org/

And to see how org-babel works :

http://orgmode.org/worg/org-contrib/babel/

深爱不及久伴 2024-10-24 22:05:40

除了通过 R 的外语接口(如果支持的话,可能通过 inline)或 system().对于它的价值,我只会使用 system();那应该很容易。

您可以查看上一个有关 Python 的 Sweave 等效项的问题,其中一位受访者实际上创建了一个单独的接口。这可以让您了解如何嵌入可能尚不支持的其他语言。至少,您必须对 Sweave 驱动程序进行重大黑客攻击。

There is certainly no easy way to do this other than through either foreign language interfaces from R (maybe through inline if it's supported), or system(). For what it's worth, I would just use system(); that should be easy enough.

You can see this previous question about having a Sweave equivalent for Python, where one of the respondents actually creates a separate interface. This can give you a sense what what it would take to embed other languages which may not already be supported. At a minimum, you have to do major hacking on the Sweave driver.

怎樣才叫好 2024-10-24 22:05:40

你知道 emacs" org-mode 吗,更具体地说,Babel?如果您已经了解 Emacs 或愿意切换到 Emacs,那么 org-mode 和 Babel 就是您问题的答案。

例如,我目前正在编写一个包含一些 shell 脚本的文档,使用 R 进行计算并使用点(graphviz)创建流程图,Org 模式可以导出多种格式,例如 LaTeX(这就是我使用的)。

Do you know emacs" org-mode and, more specifically, Babel? If you already know Emacs or are willing to switch to Emacs, then org-mode and Babel are the answer to your question(s).

For instance, I am currently working on a document which contains some shell-scripts, does computations with R and creates flow charts with dot (graphviz). Org-mode can export a variety of formats, e.g. LaTeX (that's what I use).

感情洁癖 2024-10-24 22:05:40

有一个 StatWeave 项目,它使用 java 而不是 R 来进行编织,但会运行多个程序而不仅仅是 R。我不知道让它来执行 Perl 或其他类似的程序有多难,但是主页表明它已经适用于 R、SAS、Stata 等:

http://www .cs.uiowa.edu/~rlenth/StatWeave/

There is the StatWeave project which uses java rather than R to do the weaving, but will run multiple programs instead of just R. I don't know how hard it would be to get it to do Perl or other programs like that, but the homepage indicates that it already works with R, SAS, Stata, and others:

http://www.cs.uiowa.edu/~rlenth/StatWeave/

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