通过组织模式在乳胶中嵌入R图 [英] Embedding R plots in Latex via org-mode

查看:118
本文介绍了通过组织模式在乳胶中嵌入R图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用组织模式,到目前为止,我喜欢它。我看到可以在org-mode文件中插入R,并在导出时执行它。但是我有一些麻烦让org-babel(代码嵌入)生成我感兴趣的情节,嵌入生成的图像,而不是运行代码的代码或输出。



到目前为止,我已经有了这个工作:

 #+ BABEL::session * R *:results输出图形:导出
#+ begin_src R:文件img.pdf:结果输出图形:会话* R *
hist(rnorm(100))
#+ end_src

#\includegraphics {img.pdf}

但它不如它可能。首先,它总是提示我是否要执行R代码,其次我想删除 \includegraphics 指令。



这是可能的吗?

解决方案

几件事:1)组织模式最近发生了很大变化WRT Babel和src块 - 从他们的git存储库获取最新版本(有关详细信息,请查阅常见问题)。 2)我们不再使用#+ BABEL 行,现在使用#+ PROPERTY 行完成, 3)自动完成包含图形。一个人根本不需要执行 \includegraphics {} (除非你想调整默认行为,比如说标题放置)。



例如,以下是最近版本的Org模式下,您的示例的简单版本将如下所示:

 #+ TITLE:tester.org 
#+ PROPERTY:session * R *
#+ PROPERTY:结果输出

*标题在这里

这是一些文字。

#+ begin_src R:export both:results graphics:file img.pdf
hist(rnorm(100))
#+ end_src

我刚刚在我的机器上测试,它的作用就像一个魅力。最后一件事 - 我强烈建议您订阅组织模式邮件列表,因为 您将看到正在进行的关于BABEL,PROPERTY和一大堆其他内容的讨论。 p>

顺便说一下,#+ PROPERTY:results output line并不重要,这是我通常做的,因为这更像是我从Sweave所期望的。


I'm just getting started with org-mode and so far I love it. I've seen that it is possible to insert R in the org-mode file and execute it upon export. But I have some trouble getting org-babel (the code embedding) to generate the plot I'm interested in and embed the resulting image instead of the code or the output from running the code.

So far I've got this to work:

#+BABEL: :session *R* :results output graphics :exports both
#+begin_src R :file img.pdf :results output graphics :session *R*
hist(rnorm(100))
#+end_src

#\includegraphics{img.pdf}

But it's not as nice as it could be. First it always prompts me whether I do want to execute the R code and secondly I would like to eliminate the \includegraphics instruction.

Is this possible at all?

解决方案

Few things: 1) Org mode has changed a lot recently, especially w.r.t. Babel and src blocks - get the latest version from their git repository (check the FAQ for details how to do that). 2) We don't use #+BABEL line any more, those are now done with #+PROPERTY lines, 3) The inclusion of graphics is done automatically. A person shouldn't need to do an \includegraphics{} at all (unless you want to tweak the default behavior, say, for caption placement).

For instance, here's what a simple version of your example would look like under a recent version of Org mode:

#+TITLE:    tester.org
#+PROPERTY: session *R*
#+PROPERTY: results output

* Headline here

Here is some text.

#+begin_src R :exports both :results graphics :file img.pdf
hist(rnorm(100))
#+end_src

I just tested on my machine and it works like a charm. One last thing - I highly recommend you subscribe to the Org mode mailing list, because that's the place you'll see the ongoing discussions about the BABEL, PROPERTY, and a whole bunch of other stuff.

By the way, the #+PROPERTY: results output line isn't critical, it's just what I usually do because it's more like what I expect from Sweave.

这篇关于通过组织模式在乳胶中嵌入R图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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