user3321294
user3321294

Reputation: 329

Emacs org: specify R session?

How can specify the session to use for evaluating source blocks when there are multiple R sessions? Say I have two sessions open, *R* and *R:2*. Then this

#+BEGIN_SRC R :sessions *R*
ls()
#+END_SRC

Should evaluate ls() in session *R* whereas

#+BEGIN_SRC R :sessions *R:2*
ls()
#+END_SRC

Should do the same in session *R:2* -- but it is evaluated in session *R*.

Thanks!

Upvotes: 1

Views: 208

Answers (1)

Allen Luce
Allen Luce

Reputation: 8389

Your example will work exactly as you have it with one minor change:

#+BEGIN_SRC R :session *R*
ls()
#+END_SRC

#+BEGIN_SRC R :session *R:2*
ls()
#+END_SRC

Or to make it slightly clearer:

#+BEGIN_SRC R :session *R*
wd <- getwd()
print(paste0("Current working dir: ", wd))
#+END_SRC

#+RESULTS:
: Current working dir: /private/tmp/one

#+BEGIN_SRC R :session *R:2*
wd <- getwd()
print(paste0("Current working dir: ", wd))
#+END_SRC

#+RESULTS:
: Current working dir: /private/tmp/two

Upvotes: 1

Related Questions