1

In my .emacs file, I have the following variables:

(custom-set-variables
 '(org-babel-load-languages (quote ((emacs-lisp . t) (R . t))))
 '(org-confirm-babel-evaluate nil))

I save this example to a file called "example.org":

#+TITLE: Test
#+AUTHOR: Your Name
#+EMAIL: your-email@server.com
#+PROPERTY: session *R* 
#+PROPERTY: cache yes 
#+PROPERTY: results graphics 
#+PROPERTY: exports both 
#+PROPERTY: tangle yes 

* Example of Org-Babel for R Literate Programming
** R text output
A simple summary. 
#+begin_src R 
  x <- rnorm(10)
  summary(x)
#+end_src

** R graphics output
Note we use the object =x= generated in previous code block, thanks to
the header option =:session *R*=.  The output graphics file is
=a.png=. 

#+begin_src R  :file a.png
  y <- rnorm(10)
  plot(x, y)
#+end_src

Same plot with larger dimension:

#+begin_src R  :file b.png :width 800 :height 800
  plot(x, y)
#+end_src

Then I call (org-html-export-to-html) (bound to C-c C-e h h), which generates an html file but does not run the code. What am I missing?

2

When I want to do something like that, I usually include :exports both in the header of the code block, like this:

#+begin_src R :exports both
x <- rnorm(10)
summary(x)
#+end_src

If I want it to apply to all of the source blocks, I put it it at the top of the file as:

#+PROPERTY: header-args :exports both

The various ways Org configures things in properties can be confusing. The key thing here is that the #+PROPERTY needs to specify a name and a value, and what you need to set is header-args, not an "exports" property directly.

To get your whole example working, you have to revamp all of the header arguments. A single property setting is sufficient:

#+PROPERTY: header-args :session *R* :exports both :tangle yes

That sets up your session for all the blocks, indicates that you always want to export both code and results, and that all blocks should be tangled.

You need to put :results graphics in the header for each block with a graphical output, when there is a filename specified. You can't put it in the property at the top because not all blocks specify a filename.

  • Maybe my example is an old one - I tried your modification but nothing seems to run still. – hatmatrix Dec 21 '18 at 21:48
  • 1
    Edited the answer to explain in more detail. – Win Dec 21 '18 at 22:07
  • Great - that totally works for the block that has :results output, but where I have :file I also put :results graphics and this leads to just text that says a.png and b.png; and the files themselves are empty (zero bytes). Any idea what else to try? Thanks – hatmatrix Dec 22 '18 at 3:09
  • 1
    Do you get the files generated if you evaluate the block in emacs, with ~C-c C-c~? – Win Dec 22 '18 at 22:39
  • 1
    Can you look in the buffer called *R* to see if there is an error there? – Win Dec 23 '18 at 2:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.