5

I would like to have more control on the R session in org-mode so that I only have to chage the session name in one place for the modification to affect the whole buffer. The only way I could think this through was to modify the org-babel-default-header-args.

I want to define a function so that I can modify the default arguments easily. But I don't know how to pass the name of the session as a string. see the code below.

(defun set-session-name (&optional r-session-name r-session-directory)
  (interactive (list
                (read-from-minibuffer "r-session-name: " "*R*" )
        (read-from-minibuffer "r-session-directory: " "/home/test/")))  
  (setq org-babel-default-header-args:R
    (cons '(:dir . "%s" r-session-directory))
    (cons '(:session . r-session-name) 
          (assq-delete-all :session org-babel-default-header-args:R))
          ))

(:dir . "%s" ression directory "/home/test/") is obviously wrong. Can you help please?

** Some details ** Let's say that we are in an .org buffer and I have a buffer wide header like the following. With the session name being remote-R-remote* and the ouput being silenced :output silent

 #+PROPERTY: header-args:R :session *remote-R-remote*  :exports results :colnames yes :results output silent :output-dir images/ :dir "/ssh:gnu:/home/livelygnu/Documents/R/" :eval yes :cache yes

* Some First steps

    #+Name: 
    #+BEGIN_SRC R 
    do some stuffs
    #+END_SRC

Now if in a subtree we want to produce a certain number of graphs but don't want to write :results output graphics all the time along with the file extension we have to redefine the whole header argument for this subtree.

** output some graphs
:PROPERTIES:
:header-args:R: :session *remote-R-remote* :results output graphics :output-dir: images/ :eval yes :file-ext pdf
:END:

    #+Name: name_of_graphs
    #+BEGIN_SRC R 
    plot(a)
    #+END_SRC

    many more graphs possibly

We can do the same for latex output for example

** output some results
:PROPERTIES:
:header-args:R: :session *remote-R-remote* :results output latex :output-dir: 
:END:


#+Name: name_of_graphs
#+BEGIN_SRC R 
output latex block
#+END_SRC

Now let's say while our estimation is working on the session remote-R-remote (possibly a long computation), we want to continue to work on some graphs in another session. for that we would have to change the :session names for all the code block that we need. But If instead we modify the default arguments in org-babel-default-header-args. Then changing the key :session there would change the session everywhere. Of course this mean that we would not have to write :session *remote-R-remote* all the time as well since we can put it as default.

  • So you want to give different session names based on subtree and not necessarily use a default as the default may not work for long-running sessions? If you cannot reorganize your subtrees for inheritance to solve your situation, then use a simple search and replace of session names. – Emacs User Feb 7 '17 at 15:30
  • thanks for the suggestion. But unless I'm wrong there is no such inheritance for the buffer-wide header argument. If you change the modify the header for a subtree say :output all the other buffer-wide parameters falls back to default including :session. That's why I tried to modify the defaults paremeters. The function works well but I"m switching the session name by hand directly in the function – DJJ Feb 7 '17 at 17:17
3

I'd apply the buffer wide property syntax (org-mode 9), e.g. for an R (session) buffer called *R*:

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

org-mode <9:

#+PROPERTY: session *R*

And do C-c C-c on this line to activate new settings.

  • Thanks for the try. But this would not work as i want. For example if I want to modify the header argument in a subtree through property drawer, I would have to repsecify the name of the session. As far as I know everything falls back to default if you change a parameter at the subtree level. I'm using org-mode 9. – DJJ Dec 9 '16 at 7:54
  • @DJJ, I'm sorry I don't get your use case. You asked for a way to change the R session buffer-wide, now you want to set the session per subtree. Also this is possible, but why do you want to change the sessions with a function? – Dieter.Wilhelm Dec 9 '16 at 13:34
  • Thanks for the help. I'm not sure if I'm using the best organisation as well. I've added some details in the question. – DJJ Dec 9 '16 at 14:04

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.