emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Babel][R] buffer-wide and code block specific use of :session
@ 2011-02-12 14:47 Bernd Weiss
  2011-02-12 18:30 ` Dan Davison
  0 siblings, 1 reply; 3+ messages in thread
From: Bernd Weiss @ 2011-02-12 14:47 UTC (permalink / raw)
  To: emacs-orgmode

Org-mode version 7.4 (release_7.4.348.g6132)


Dear all,

I am preparing a document which contains text and R code/output. In 
particular, I'd like to print out a (correlation) matrix. This is my 
org-mode document (I intentionally have two code blocks):

#----------------------------------------------------------
#+ Does not work

#+BABEL: :session *R*
#+BEGIN_SRC R :results silent :tangle simcorrdata.R
cormat <- c(1.0,  0.2,  0.4,
             0.2,  1.0, -0.3,
             0.4, -0.3,  1.0)
cormat <- matrix(cormat, ncol = 3, byrow = TRUE)
#+END_SRC

So, the correlation matrix looks as follows:

#+BEGIN_SRC R :exports both :tangle simcorrdata.R
print(cormat)
#+END_SRC
#----------------------------------------------------------

Since I have two code blocks, I need to use :session. If I define 
:session buffer-wide as

#+BABEL: :session *R*

then the matrix cormat is unknown within the second code block ("object 
'cormat' not found"). However, if I specify :session for each code block 
seperately then it works as expected.

#----------------------------------------------------------
#+ Does work

#+BEGIN_SRC R :session :results silent :tangle simcorrdata.R
cormat <- c(1.0,  0.2,  0.4,
             0.2,  1.0, -0.3,
             0.4, -0.3,  1.0)
cormat <- matrix(cormat, ncol = 3, byrow = TRUE)
#+END_SRC

So, the correlation matrix looks as follows:

#+BEGIN_SRC R :session :exports both :tangle simcorrdata.R
print(cormat)
#+END_SRC
#----------------------------------------------------------


Does this happen due to my poor understanding of the :session argument? 
Or is this a bug?

Thanks for your help,

Bernd

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Babel][R] buffer-wide and code block specific use of :session
  2011-02-12 14:47 [Babel][R] buffer-wide and code block specific use of :session Bernd Weiss
@ 2011-02-12 18:30 ` Dan Davison
  2011-02-12 20:42   ` Bernd Weiss
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Davison @ 2011-02-12 18:30 UTC (permalink / raw)
  To: Bernd Weiss; +Cc: emacs-orgmode

Bernd Weiss <bernd.weiss@uni-koeln.de> writes:

> Org-mode version 7.4 (release_7.4.348.g6132)
>
>
> Dear all,
>
> I am preparing a document which contains text and R code/output. In 
> particular, I'd like to print out a (correlation) matrix. This is my 
> org-mode document (I intentionally have two code blocks):
>
> #----------------------------------------------------------
> #+ Does not work
>
> #+BABEL: :session *R*
> #+BEGIN_SRC R :results silent :tangle simcorrdata.R
> cormat <- c(1.0,  0.2,  0.4,
>              0.2,  1.0, -0.3,
>              0.4, -0.3,  1.0)
> cormat <- matrix(cormat, ncol = 3, byrow = TRUE)
> #+END_SRC
>
> So, the correlation matrix looks as follows:
>
> #+BEGIN_SRC R :exports both :tangle simcorrdata.R
> print(cormat)
> #+END_SRC
> #----------------------------------------------------------
>
> Since I have two code blocks, I need to use :session. If I define 
> :session buffer-wide as
>
> #+BABEL: :session *R*
>
> then the matrix cormat is unknown within the second code block ("object 
> 'cormat' not found"). However, if I specify :session for each code block 
> seperately then it works as expected.

Hi Bernd,

The above does work for me. Some things to check:

1. After altering the #+BABEL line, it's necessary to refresh Org's
   file-local options, for example with C-c C-c on the #+BABEL
   line. (Same is true for #+OPTIONS, #+PROPERTY, etc)

2. I've just fixed a bug which was causing it to fail to work on the
   first attempt... But it did work on second and subsequent attempts.

Please note that it is possible to make an equivalent setting using 

#+PROPERTY: session *R*

In fact, I suspect we are going to drop #+BABEL entirely, so please
consider it deprecated and use this form instead.

After evaluating the first block, an ESS R buffer named *R* should
exist, in which the variable cormat should be defined. Let me know if
your problem persists.

Dan


>
> #----------------------------------------------------------
> #+ Does work
>
> #+BEGIN_SRC R :session :results silent :tangle simcorrdata.R
> cormat <- c(1.0,  0.2,  0.4,
>              0.2,  1.0, -0.3,
>              0.4, -0.3,  1.0)
> cormat <- matrix(cormat, ncol = 3, byrow = TRUE)
> #+END_SRC
>
> So, the correlation matrix looks as follows:
>
> #+BEGIN_SRC R :session :exports both :tangle simcorrdata.R
> print(cormat)
> #+END_SRC
> #----------------------------------------------------------
>
>
> Does this happen due to my poor understanding of the :session argument? 
> Or is this a bug?
>
> Thanks for your help,
>
> Bernd
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Babel][R] buffer-wide and code block specific use of :session
  2011-02-12 18:30 ` Dan Davison
@ 2011-02-12 20:42   ` Bernd Weiss
  0 siblings, 0 replies; 3+ messages in thread
From: Bernd Weiss @ 2011-02-12 20:42 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-orgmode

Am 12.02.2011 13:30, schrieb Dan Davison:
> Bernd Weiss<bernd.weiss@uni-koeln.de>  writes:

[...]

>> Since I have two code blocks, I need to use :session. If I define
>> :session buffer-wide as
>>
>> #+BABEL: :session *R*
>>
>> then the matrix cormat is unknown within the second code block ("object
>> 'cormat' not found"). However, if I specify :session for each code block
>> seperately then it works as expected.
>
> Hi Bernd,
>
> The above does work for me. Some things to check:
>
> 1. After altering the #+BABEL line, it's necessary to refresh Org's
>     file-local options, for example with C-c C-c on the #+BABEL
>     line. (Same is true for #+OPTIONS, #+PROPERTY, etc)
>
> 2. I've just fixed a bug which was causing it to fail to work on the
>     first attempt... But it did work on second and subsequent attempts.
>
> Please note that it is possible to make an equivalent setting using
>
> #+PROPERTY: session *R*
>
> In fact, I suspect we are going to drop #+BABEL entirely, so please
> consider it deprecated and use this form instead.
>
> After evaluating the first block, an ESS R buffer named *R* should
> exist, in which the variable cormat should be defined. Let me know if
> your problem persists.

Hi Dan,

Thanks for your reply. Using

#+PROPERTY: session *R*

(and running another =git pull origin master=) solved all my problems.

Thanks,

Bernd

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-02-12 20:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-12 14:47 [Babel][R] buffer-wide and code block specific use of :session Bernd Weiss
2011-02-12 18:30 ` Dan Davison
2011-02-12 20:42   ` Bernd Weiss

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).