1

I would like all R src blocks in an org file to use the same session interactively and have included a minimal example below. I added the #+PROPERTY line as in the manual and ran C-c C-c as suggested in the related questions to ensure the property takes effect, but it does not seem to work when trying to run src blocks in an interactive manner (i.e. running C-c C-c on the src blocks)

I am unsure what I am missing or misunderstanding. Is it possible to use file-level properties for interactively running src blocks?

Cannot add general block header arguments in org mode

Org-babel: using properties as code block header arguments, how to make it work?

Org manual

#+title: Test
#+PROPERTY: header-args:R:  :session *R*

Load a library in one block

#+begin_src R
library(dplyr)
#+end_src

#+RESULTS:
| dplyr     |
| stats     |
| graphics  |
| grDevices |
| utils     |
| datasets  |
| methods   |
| base      |

Try to use a function from that library in another block

#+begin_src R
mtcars %>% filter(cyl == 4)
#+end_src

Executing the above with C-c C-c fails because it cannot find ~%>%~, so the two src blocks must be running in
independent sessions.

Error in mtcars %>% filter(cyl == 4) : could not find function "%>%"
Calls: <Anonymous> -> <Anonymous>
Execution halted

2
  • No colon after header-args:R - see manual : #+PROPERTY: header-args:R :session *R*
    – NickD
    Commented Nov 4, 2022 at 18:21
  • Doh. Thanks NickD, that did it. If you'd like to make that an answer I will accept.
    – ejneer
    Commented Nov 4, 2022 at 21:24

1 Answer 1

2

[Expanding the comment into an answer]

There should be no colon after header-args:R:

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

It's true that all those colons are confusing, but they are important, so you might want to get the syntax "into your fingers" so to speak.

  • The PROPERTY keyword is always followed by a colon.
  • The property name is never followed by a colon. In this case, the property name is header-args:R.
  • The property value in the case of header-args is a sequence of header args, each of which starts with a colon.

In general, property values are arbitrary strings, but header-args (either bare or qualified by a language) have stricter requirements.

The manual shows an R example, but does not quite define the syntax: the property name is header-args:<LANG> where <LANG> is the same string as the one you use in a #+BEGIN_SRC ... #+END_SRC block. So in this case, it should be header-args:R.

I'm not sure how Org mode parsed header-args:R: - I assume it thought the <LANG> component was R: and, looking for such source blocks, it did not find any, so the setting was ignored.

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.