emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Greg Minshall <minshall@umich.edu>
To: John Kitchin <jkitchin@andrew.cmu.edu>
Cc: tomas@tuxteam.de, emacs-orgmode@gnu.org
Subject: Re: Get =#+RESULTS= without re-evaluating source code block?
Date: Thu, 28 Jan 2021 06:26:17 +0300	[thread overview]
Message-ID: <1342984.1611804377@apollo2.minshall.org> (raw)
In-Reply-To: Your message of "Wed, 27 Jan 2021 18:31:03 -0500." <CAJ51ETpWnQrr6fVH26B5dMPU6ucw2M3Mn3pCWzERUCCXkwapiA@mail.gmail.com>

John,

> I tried this but it did not work for me.

to be clear, caching means that the *first* time you execute, your
reference will have to wait for the long-running computation to
complete, but not during subsequent executions (unless the source block
that performs the execution changes, in which case the reference will
again have to wait).

also, caching means that, after the first execution (ditto caveat) the
source block *will no longer run*.  so, if there were any (other) side
effects of running that source block, they will not happen.  (you could
possibly split the side effect-producing code out of that block.)

i'm not sure if this explains what did not work for you.

cheers, Greg

> 
> 
> On Wed, Jan 27, 2021 at 5:38 PM <tomas@tuxteam.de> wrote:
> 
> > On Wed, Jan 27, 2021 at 05:14:43PM -0500, doltes wrote:
> > > Get =#+RESULTS= without re-evaluating source code block?
> > >
> > > Let's suppose I have a code block which requires a long time to finish
> > >
> > > #+NAME: big-computation
> > > #+begin_src bash
> > > sleep 5 # Some computation which requires a long time to complete.
> > > echo a
> > > #+end_src
> > >
> > > #+RESULTS: big-computation
> > > #+begin_example
> > > a
> > > #+end_example
> > >
> > > I want to use the results of that code block in other code blocks so I
> > > use a =noweb= reference (see below.)
> > >
> > > #+begin_src bash :noweb yes
> > > printf "%s\n" <<big-computation()>>
> > > #+end_src
> > >
> > > #+RESULTS:
> > > #+begin_example
> > > a
> > >
> > > #+end_example
> > >
> > > However, doing this (i.e. using a =noweb= reference) would make the
> > > command to be evaluated whenever getting its results. I don't want
> > > this, I want the =:noweb= reference to actually use the already
> > > computed results.
> > >
> > > So, my question is: Is it possible to use the actual =#+RESULTS= code
> > > block instead of always evaluating it when referencing the results
> > > through a =:noweb= reference?
> >
> > Perhaps "Cache results of evaluation" (15.5 Evaluating Code Blocks,
> > in the Interwebs here [1] is for you.
> >
> > In short, add a header argument :cache yes to your code block.
> >
> > Cheers
> >
> > [1] https://orgmode.org/org.html#Evaluating-Code-Blocks
> >
> >  - t
> >
> -- 
> John
> 
> -----------------------------------
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu


  reply	other threads:[~2021-01-28  3:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27 22:14 doltes
2021-01-27 22:38 ` tomas
2021-01-27 23:31   ` John Kitchin
2021-01-28  3:26     ` Greg Minshall [this message]
2021-02-02  2:10       ` John Kitchin
2021-02-02 20:02         ` Nick Dokos
2021-01-27 23:33   ` doltes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1342984.1611804377@apollo2.minshall.org \
    --to=minshall@umich.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=jkitchin@andrew.cmu.edu \
    --cc=tomas@tuxteam.de \
    --subject='Re: Get =#+RESULTS= without re-evaluating source code block?' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).