Org Mode's Babel for executing code blocks provides two header arguments, :output-dir
and :file-ext
that were clearly intended to be used in the global document header, applying to all blocks. They enable Org to auto-generate the names of files that are produced by the blocks - most commonly, I guess, graphics.
This works fine for graphics blocks, as intended. They allow easy switching between graphics formats. However, it also seems to mean that ALL blocks now save their results in a file, even where this is not appropriate (e.g. the block calculates a single value, which should be inserted directly into the document).
Am I missing something, or is this just a limitation, that these useful global arguments can't be used if a document happens to produce a mixture of tables and charts?
#+TITLE: Don't export EVERYTHING as a pdf
#+PROPERTY: header-args:R :output-dir charts :file-ext pdf
The :output-dir and :file specify the directory and file extension that should be used to save output of all blocks. However, this results in ALL blocks' output being saved to files, even where this is not appropriate.
#+NAME: code_that_should_output_a_value
#+BEGIN_SRC R :exports results :results value
dat <- data.frame( a=1:3, b=10:12)
sum(dat$a)
#+END_SRC
#+RESULTS: code_that_should_output_a_value
[[file:charts/code_that_should_output_a_value.pdf]]
Update: I asked on the mailing list: http://lists.gnu.org/archive/html/emacs-orgmode/2018-05/msg00466.html What emerged:
- setting
:file-ext
indeed sets:results file
for all blocks. So if it's used as a global header, all blocks will be forced to output files, whether wanted or not. :file-ext
was originally envisioned for use at block level - to automatically generate file names in combination with#+NAME:
and possibly:output-dir
.- The current behaviour is not seen as ideal, and may well be changed in Org 10.0 (but not straight away, to maintain backwards compatibility with existing documents)