In org-mode, if I set the :file header-arg at some point, like all header args, it is inherited at lower levels. I want to avoid duplicating the header-arg all over. In the case of :session, the special value none is used to not associate the code block with any existing session, it s always a new session. I want the special value for :file, which represents do not write this to a file, but insert it directly as usual.

* set at top header level
  :header-args: :R :file "abcd.pdf" :exports both :results output graphics

x = seq( from = -2, to = 2, by = 0.1)
plot (x,x^2,col="red", type="l")

** lower level header 
# output still goes to abcd.pdf, but I don't want it to, I want it inserted
2 + 2
  • I'm not 100% sure I followed what you wanted to do, but edited the post to make it clearer. If I misunderstood what you wanted to do, we can roll back the changes. – Dan Feb 17 '16 at 15:47
  • I'll rewrite it. Or maybe it's better to have a new question. Kind of missed the point. This is specific to the :file header in org-mode. – mhb Feb 18 '16 at 7:08
  • Can you not rewrite the :file argument on a block by block basis? – Dan Feb 18 '16 at 10:24
  • 1
    Rewrite it to what to make it not output? – mhb Feb 19 '16 at 3:57

It looks like you can override the PROPERTY default values on a block-by-block basis:

#+PROPERTY: header-args:R :session *R* :results output 

  #+name: data-setup-silently
  #+begin_src R :results silent
    x <- 1:10

  #+name: results-silently
  #+begin_src R :results silent

  #+name: results
  #+begin_src R 


  • The PROPERTY sets the default :results to output
  • Block 1: set up the data, and override with silent to shut up about it
  • Block 2: print out the results, but override with silent to prevent results from being added to the buffer
  • Block 3: default behavior: print out the results to the buffer
  • 1
    How does this cover the op's case, switching back and forth from file output to buffer? – Emacs User May 18 '16 at 19:11

My solution to this problem is to set up yasnippets with a few different header arguments. It works well as long as you only have a few different options and use only 1 or 2 languages.

  • Welcome to Emacs.SE! Could you provide a little more detail in your answer to show how to implement it? For example, please consider posting the snippets you use. – Dan Feb 16 '16 at 20:24
  • The question is not how to handle different header arguments, but what arguments can switch output from file to buffer in subsequent blocks. – Emacs User May 18 '16 at 19:14

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.