0

I am trying to setup like the following in the top section of my .org file. But it does not work, all the parameters are not passed into the subsequent R code blocks.

 #+BABEL: :session *R* :cache yes :results output graphics :exports both :tangle yes

Doing like the following works. But it forces every code block to have :file parameter set. I don't want that because I have some code blocks which do not have graphic output.

#+PROPERTY: session *R*
#+PROPERTY: cache yes
#+PROPERTY: results graphics
#+PROPERTY: exports both
#+PROPERTY: tangle yes

How do I setup this? I prefer one-liner setup like "+BABEL:...." and customize the code blocks that I want differently.

2 Answers 2

2

One solution may be to add a PROPERTIES drawer at the heading level e.g.

:PROPERTIES:
:header-args: :session *R* :cache yes :results output graphics :exports both :tangle yes
:END:

If you do this, you cannot override individual parameters with another header-args in a PROPERTIES drawer as this overrides the whole line, but you can override indivudal parameters on the #+begin_src declaration.

4
  • This works for all paramenters in there, except for the session *R* part. I still have to use the #+PROPERTY: session *R* syntax. Commented Sep 19, 2016 at 13:35
  • That's odd - I don't use session much (prefer code blocks idempotent) but I can't see a reason why it would be different. The session arg just gives a name to the session does it not. Random guess: maybe something else is interpreting the * - can you try calling it something different?
    – Matt Innes
    Commented Sep 21, 2016 at 11:15
  • Can you elaborate your setup? I have no reason to stick to the non-working setup. With that said, reading through the latest orgmode docs, this should work but I haven't tried: ` #+PROPERTY: header-args:R :session *R*` Commented Sep 21, 2016 at 18:35
  • I've been using something similar for SQL - this allows me to define the database parameters at the heading level then just write SQL in src blocks and it just works - but I don't need sessions. The header-args:R syntax is to specifiy particular args are relevent to particular languages - if session in this instance is an R specific arg then that may fix your issue. :PROPERTIES: :header-args: :engine "mysql" :dbuser "dbuser" :dbpassword "password" :dbhost "192.168.32.216" :database "dbname" :var dbuser="dbuser" :END:
    – Matt Innes
    Commented Sep 22, 2016 at 10:34
0

Attempting to improve on the previous answer:

One solution is to use #+PROPERTY :header-args: for file level parameters. For example:

#+PROPERTY: :header-args:R :session *R* :cache yes :results output graphics :exports both :tangle yes

Another solution may be to add a PROPERTIES drawer at the heading level, for example:

:PROPERTIES:
:header-args:R :session *R* :cache yes :results output graphics :exports both :tangle yes
:END:

Furthermore, you can override :header-args: at lower entries via the concatenation mechanism:

* Top Level
:PROPERTIES:
:header-args:R :session *R* :cache yes :results output graphics :exports both :tangle yes
:END:

** With Overrides
:PROPERTIES:
:header-args:R+ :cache no
:END:

Similarly, each source block can contain overrides, as well.

I am constantly referring to https://org-babel.readthedocs.io/en/latest/header-args/ to aid in my babel quests.

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.