I have a code block with a simple command:
#+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
I load ggplot2 in an earlier block of this session, and it works fine when I do C-c C-c to execute that block.
When I try C-c C-e h or C-c C-e P to export or publish the file, it writes an a.png of length 0.
Here are some of the #+ lines at the start of this file:
#+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
I’m running “GNU Emacs 23.3.1 (i386-mingw-nt5.2.3790) of 2011-03-10 on 3249CTO” on an XP64 system and “Org-mode version 7.5”.
What am I missing? I didn’t find the answer in my search of Stack Overflow, the org-mode mailing list, the manuals, or Google.
I tried a simple, executable file this morning:
#+TITLE: test.org
#+AUTHOR:
#+EMAIL: me
#+DATE: 2012-03-01 Thu
#+DESCRIPTION:
#+KEYWORDS:
#+LANGUAGE: en
#+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:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+LINK_UP:
#+LINK_HOME:
#+XSLT:
#+BABEL: :session *R* :cache yes :exports both :tangle yes
* Test of R
#+begin_src R :results output :export both
summary(rnorm(25))
#+end_src
#+results:
* Test of ggplot2
#+begin_src R :results output graphics :exports results :file testggplot.png
library(ggplot2)
qplot(runif(25))
#+end_src
Each code block executes fine with C-c C-c. Running C-c C-e h or C-c C-e b to export as HTML gives problems with a big clue: it writes the file testggplot.png with the contents
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
My conjecture: I got a 0-length .png file above because it didn’t need to write an error message.
If I run C-c C-c first, I get a #+results[ section in the .org file with a link to testggplot.png. I can see the graph in the .org file, if I turn on iimage-mode.
If I then run C-c C-e h, I get a valid HTML file with the graph.
Does that (or the ECM) give any clues that might show me what to do (besides running C-c C-c on every code block first)?
UPDATE 2: perhaps snippets of the HTML org-mode produces provide insight.
If I have run C-c C-c first, such that the graphic file has been written, then I get
<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>
If I have not created the file first, then I get
<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>
The only difference seems to be whether it wraps the file name in a <pre> block as text or whether it wraps it as an image. Of course, in the first case, it also fails to write a .png file.
I have no problems with your
test.orgexample.First, you are using a pretty old version of org-mode. My version is 7.8… (Org-mode version 7.8.03 (release_7.8.03.484.ge4ac3)).
Second, please note that the syntax for setting (buffer-wide) header arguments has changed. It is no longer
#+BABELetc. See “Header arguments in Org mode properties” for more information. In your case it would look like