emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Question about using :cache in Babel (for R)
@ 2011-09-27 20:53 Michael Hannon
  2011-09-28  0:42 ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Hannon @ 2011-09-27 20:53 UTC (permalink / raw)
  To: Org-Mode List

[-- Attachment #1: Type: text/plain, Size: 1969 bytes --]

Greetings.  I have a question that relates to the use of the :cache option in
Babel sessions using R.

Here's the relevant configuration information:

    Emacs  : GNU Emacs 23.2.1 (x86_64-redhat-linux-gnu, GTK+ Version 2.24.4)
     of 2011-05-23 on x86-12.phx2.fedoraproject.org
    Package: Org-mode version 7.7 (release_7.7.328.g1a97)

I've appended the text of a file that exhibits the issue, which is the
following.  If I explicitly evaluate a given code block, using, let's say, C-c
C-c, I get the results stuck into the Org file, as in the first source-code
block below.  If I then repeatedly export the file (to PDF, HTML, etc.), I get
the cached results in the exported document.  For instance, the mean of the
random variable does not change as I repeatedly export the file.

If for some reason I have NOT explicitly evaluated a given code block, as with
the second code block below, then during export I see a message "Evaluating
code block" (or similar), indicating that Babel is NOT using a cached version,
and no cacheable output is produced as a result, meaning that the entire
calculation will be repeated during the next export.  For instance, the mean
of the random variable will be different every time I export the file.

I guess I can see the logic of this, but I wonder if there is some way to
instruct Babel to automatically cache the output of any code blocks it
evaluates, i.e., via a header argument or elisp variable or ... .

Thanks,

-- Mike

P.S. Is the SHA1(?) identifier for the results a new feature?

----------

#+TITLE: 
#+AUTHOR:
#+DATE:

#+STARTUP: hideblocks
#+BABEL: :session *R* :cache yes :results output verbatim :exports both
:tangle yes

* This is a test

#+begin_src R

  x = rnorm(10)
  mean(x)

#+end_src

#+results[9b9372488662083d0d211b9aad9c2985faba20cd]:
: [1] -0.07904561

* Here's a second test

#+begin_src R

  x = rnorm (50)
  summary(x)

#+end_src

[-- Attachment #2: Type: text/html, Size: 7611 bytes --]

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

* Re: Question about using :cache in Babel (for R)
  2011-09-27 20:53 Question about using :cache in Babel (for R) Michael Hannon
@ 2011-09-28  0:42 ` Eric Schulte
  2011-09-28  3:14   ` Michael Hannon
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Schulte @ 2011-09-28  0:42 UTC (permalink / raw)
  To: Michael Hannon; +Cc: Org-Mode List

Michael Hannon <jm_hannon@yahoo.com> writes:

> Greetings.  I have a question that relates to the use of the :cache option in
> Babel sessions using R.
>
> Here's the relevant configuration information:
>
>     Emacs  : GNU Emacs 23.2.1 (x86_64-redhat-linux-gnu, GTK+ Version 2.24.4)
>      of 2011-05-23 on x86-12.phx2.fedoraproject.org
>     Package: Org-mode version 7.7 (release_7.7.328.g1a97)
>
> I've appended the text of a file that exhibits the issue, which is the
> following.  If I explicitly evaluate a given code block, using, let's say, C-c
> C-c, I get the results stuck into the Org file, as in the first source-code
> block below.  If I then repeatedly export the file (to PDF, HTML, etc.), I get
> the cached results in the exported document.  For instance, the mean of the
> random variable does not change as I repeatedly export the file.
>
> If for some reason I have NOT explicitly evaluated a given code block, as with
> the second code block below, then during export I see a message "Evaluating
> code block" (or similar), indicating that Babel is NOT using a cached version,
> and no cacheable output is produced as a result, meaning that the entire
> calculation will be repeated during the next export.  For instance, the mean
> of the random variable will be different every time I export the file.
>

Hi Mike,

This is the expected behavior.  Org-mode files are just plain text, so
if the results are not saved in the Org-mode file then there is no place
to cache them.  Since Org does not change the contents of Org-mode files
the only way to save the result of a code block is to interactively
evaluate the code block -- there is no way to generate and save cached
results during export.

>
> I guess I can see the logic of this, but I wonder if there is some way to
> instruct Babel to automatically cache the output of any code blocks it
> evaluates, i.e., via a header argument or elisp variable or ... .
>

Nope, in the past we have played with things like an in-memory variable,
but have abandoned such things as they would move away from the "just
plain text" spirit of Org-mode, would require external storage on disk,
and could ultimately lead to more confusing behavior than the current
situation.

>
> Thanks,
>
> -- Mike
>
> P.S. Is the SHA1(?) identifier for the results a new feature?
>

No, this is how Babel knows if the contents of the code block have
changed and hence if the cached results are still valid.

Best -- Eric

>
> ----------
>
> #+TITLE: 
> #+AUTHOR:
> #+DATE:
>
> #+STARTUP: hideblocks
> #+BABEL: :session *R* :cache yes :results output verbatim :exports both
> :tangle yes
>
> * This is a test
>
> #+begin_src R
>
>  x = rnorm(10)
>  mean(x)
>
> #+end_src
>
> #+results[9b9372488662083d0d211b9aad9c2985faba20cd]:
> : [1] -0.07904561
>
> * Here's a second test
>
> #+begin_src R
>
>  x = rnorm (50)
>  summary(x)
>
> #+end_src

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

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

* Re: Question about using :cache in Babel (for R)
  2011-09-28  0:42 ` Eric Schulte
@ 2011-09-28  3:14   ` Michael Hannon
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Hannon @ 2011-09-28  3:14 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org-Mode List

[-- Attachment #1: Type: text/plain, Size: 3492 bytes --]

Thanks, Eric.  That's very clear.  (This is a great list.)

-- Mike



>________________________________
>From: Eric Schulte <schulte.eric@gmail.com>
>To: Michael Hannon <jm_hannon@yahoo.com>
>Cc: Org-Mode List <emacs-orgmode@gnu.org>
>Sent: Tuesday, September 27, 2011 5:42 PM
>Subject: Re: [O] Question about using :cache in Babel (for R)
>
>Michael Hannon <jm_hannon@yahoo.com> writes:
>
>> Greetings.  I have a question that relates to the use of the :cache option in
>> Babel sessions using R.
>>
>> Here's the relevant configuration information:
>>
>>     Emacs  : GNU Emacs 23.2.1 (x86_64-redhat-linux-gnu, GTK+ Version 2.24.4)
>>      of 2011-05-23 on x86-12.phx2.fedoraproject.org
>>     Package: Org-mode version 7.7 (release_7.7.328.g1a97)
>>
>> I've appended the text of a file that exhibits the issue, which is the
>> following.  If I explicitly evaluate a given code block, using, let's say, C-c
>> C-c, I get the results stuck into the Org file, as in the first source-code
>> block below.  If I then repeatedly export the file (to PDF, HTML, etc.), I get
>> the cached results in the exported document.  For instance, the mean of the
>> random variable does not change as I repeatedly export the file.
>>
>> If for some reason I have NOT explicitly evaluated a given code block, as with
>> the second code block below, then during export I see a message "Evaluating
>> code block" (or similar), indicating that Babel is NOT using a cached version,
>> and no cacheable output is produced as a result, meaning that the entire
>> calculation will be repeated during the next export.  For instance, the mean
>> of the random variable will be different every time I export the file.
>>
>
>Hi Mike,
>
>This is the expected behavior.  Org-mode files are just plain text, so
>if the results are not saved in the Org-mode file then there is no place
>to cache them.  Since Org does not change the contents of Org-mode files
>the only way to save the result of a code block is to interactively
>evaluate the code block -- there is no way to generate and save cached
>results during export.
>
>>
>> I guess I can see the logic of this, but I wonder if there is some way to
>> instruct Babel to automatically cache the output of any code blocks it
>> evaluates, i.e., via a header argument or elisp variable or ... .
>>
>
>Nope, in the past we have played with things like an in-memory variable,
>but have abandoned such things as they would move away from the "just
>plain text" spirit of Org-mode, would require external storage on disk,
>and could ultimately lead to more confusing behavior than the current
>situation.
>
>>
>> Thanks,
>>
>> -- Mike
>>
>> P.S. Is the SHA1(?) identifier for the results a new feature?
>>
>
>No, this is how Babel knows if the contents of the code block have
>changed and hence if the cached results are still valid.
>
>Best -- Eric
>
>>
>> ----------
>>
>> #+TITLE: 
>> #+AUTHOR:
>> #+DATE:
>>
>> #+STARTUP: hideblocks
>> #+BABEL: :session *R* :cache yes :results output verbatim :exports both
>> :tangle yes
>>
>> * This is a test
>>
>> #+begin_src R
>>
>>  x = rnorm(10)
>>  mean(x)
>>
>> #+end_src
>>
>> #+results[9b9372488662083d0d211b9aad9c2985faba20cd]:
>> : [1] -0.07904561
>>
>> * Here's a second test
>>
>> #+begin_src R
>>
>>  x = rnorm (50)
>>  summary(x)
>>
>> #+end_src
>
>-- 
>Eric Schulte
>http://cs.unm.edu/~eschulte/
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 4820 bytes --]

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

end of thread, other threads:[~2011-09-28  3:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-27 20:53 Question about using :cache in Babel (for R) Michael Hannon
2011-09-28  0:42 ` Eric Schulte
2011-09-28  3:14   ` Michael Hannon

Code repositories for project(s) associated with this 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).