为什么org babel导出ggplot图时可以使用C-C C-C,但不能使用导出或发布?

为什么org babel导出ggplot图时可以使用C-C C-C,但不能使用导出或发布?,r,ggplot2,org-mode,R,Ggplot2,Org Mode,我有一个带有简单命令的代码块: #+begin_src R :results output graphics :exports results :file a.png print(qplot(a,binwidth=1)+opts(title="graph title")+scale_x_continuous("axis lable")+scale_y_continuous(formatter="comma")) #+end_src 我将ggplot2加载到这个会话的前一个块中,当我执行该块时,

我有一个带有简单命令的代码块:

#+begin_src R :results output graphics :exports results :file a.png
print(qplot(a,binwidth=1)+opts(title="graph title")+scale_x_continuous("axis lable")+scale_y_continuous(formatter="comma"))
#+end_src
我将ggplot2加载到这个会话的前一个块中,当我执行该块时,它可以正常工作

当我尝试导出或发布文件时,它会写入长度为0的a.png

以下是此文件开头的一些
#+
行:

#+OPTIONS:   H:3 num:t toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS:   TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+INFOJS_OPT: view:info toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+BABEL: :session *R* :cache yes :exports both :tangle yes
我的猜测是:我在上面得到了一个0长度的.png文件,因为它不需要编写错误消息

如果我先运行
C-C-C
,我会在.org文件中得到一个
#+results[
部分,其中有一个指向
testggplot.png
的链接。如果我打开iimage模式,我可以在.org文件中看到图形

如果我随后运行
C-C-e h
,我会得到一个带有图形的有效HTML文件

这(或ECM)是否提供了任何可能告诉我该怎么做的线索(除了先在每个代码块上运行
C-C-C

更新2:也许HTML组织模式产生的片段提供了洞察力

如果我先运行了
C-C-C
,这样图形文件就被写入了,那么我就得到了

<div id="outline-container-2" class="outline-2">
<h2 id="sec-2"><span class="section-number-2">2</span> Test of ggplot2 </h2>
<div class="outline-text-2" id="text-2">


<p>
<img src="testggplot.png"  alt="testggplot.png" />
</p>







</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2"><span class="section-number-2">2</span> Test of ggplot2 </h2>
<div class="outline-text-2" id="text-2">


<pre class="example">
testggplot.png
</pre>










</div>
</div>

2 ggplot2的测试

如果我没有先创建文件,那么我会

<div id="outline-container-2" class="outline-2">
<h2 id="sec-2"><span class="section-number-2">2</span> Test of ggplot2 </h2>
<div class="outline-text-2" id="text-2">


<p>
<img src="testggplot.png"  alt="testggplot.png" />
</p>







</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2"><span class="section-number-2">2</span> Test of ggplot2 </h2>
<div class="outline-text-2" id="text-2">


<pre class="example">
testggplot.png
</pre>










</div>
</div>

2 ggplot2的测试
testggplot.png

唯一的区别似乎是它是将文件名包装在
块中作为文本还是将其包装为图像。当然,在第一种情况下,它也无法写入.png文件。

我对您的
test.org
示例没有任何问题

# Babel settings
#+PROPERTY: session *R*
#+PROPERTY: cache yes 
#+PROPERTY: exports both
#+PROPERTY: tangle yes
首先,您使用的是一个非常旧的组织模式版本。我的版本是7.8…(组织模式版本7.8.03(release_7.8.03.484.ge4ac3))

其次,请注意,设置(缓冲区范围)头参数的语法已更改。它不再是
#+BABEL
等。有关详细信息,请参阅“”。在您的情况下


谢谢,Bernd。我知道它很旧;我在家里更新了更旧的版本(GNU/Linux)我昨晚抓到了最新的ELPA tarball,它抱怨它无法导出,所以我对盲目更新有点紧张。我会进一步检查。也感谢新语法。我使用的语法应该在7.5中有效,对吧?变更日志似乎显示更改在7.8中有效。我刚刚升级到7.8.03,它在7.5中有效e测试用例。它在实际情况下还不起作用,但我认为这是一个不同的问题,与我的R脚本有关,而不是与组织模式有关。谢谢!