5

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
  :PROPERTIES:
  :header-args: :R :file "abcd.pdf" :exports both :results output graphics
  :END:

#+BEGIN_SRC R 
x = seq( from = -2, to = 2, by = 0.1)
plot (x,x^2,col="red", type="l")
#+END_SRC

** lower level header 
# output still goes to abcd.pdf, but I don't want it to, I want it inserted
#+BEGIN_SRC R 
2 + 2
#+END_SRC
4
  • 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
    Commented Feb 17, 2016 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
    Commented Feb 18, 2016 at 7:08
  • Can you not rewrite the :file argument on a block by block basis?
    – Dan
    Commented Feb 18, 2016 at 10:24
  • 1
    Rewrite it to what to make it not output?
    – mhb
    Commented Feb 19, 2016 at 3:57

2 Answers 2

1

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

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

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

  #+name: results-silently
  #+begin_src R :results silent
     print(x)
  #+end_src

  #+name: results
  #+begin_src R 
     print(x)
  #+end_src

Here:

  • 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
  • 1
    How does this cover the op's case, switching back and forth from file output to buffer?
    – Emacs User
    Commented May 18, 2016 at 19:11
-1

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.

2
  • 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
    Commented Feb 16, 2016 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
    Commented May 18, 2016 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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