emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Greg Minshall <minshall@umich.edu>
To: Naresh Gurbuxani <naresh_gurbuxani@hotmail.com>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: Efficiently reuse code in org babel with R
Date: Thu, 07 Jul 2022 09:22:35 +0300	[thread overview]
Message-ID: <3043697.1657174955@apollo2.minshall.org> (raw)
In-Reply-To: <BL0PR01MB403676CB85EEA1AD5724F07AFA839@BL0PR01MB4036.prod.exchangelabs.com>

Naresh,

> I want to source some data from databases, then use this data in
> various blocks.  I am looking for the most efficient way to achieve
> this.  In below blocks, is the code in block ``connection'' executed
> thrice (economy of code but no saving of time) or is it only executed
> once then used twice?  If the code is run thrice, is there another way
> to create code blocks so that the code is executed only once?

if you export this "file", the "connection" block will execute three
times.

Vikas suggested a session, which is something i often do for interactive
work.

or, the R code in "connection" could also use R variables to protect
itself against multiple executions.

or, i suppose you could invoke "connection" via a :var variable (rather
than via =<<connection>>), and use the :cache keyword to restrict
connection's evaluation to "every now and then" (for a very
precisely-defined, if not always intuitively definition of "every now
and then").  you'd have to be careful to not get bitten by the code
*not* being evaluated, and by it being evaluated too often.  (probably
too clever by half.)

hth, cheers, Greg


      parent reply	other threads:[~2022-07-07  6:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07  3:31 Efficiently reuse code in org babel with R Naresh Gurbuxani
2022-07-07  4:15 ` Vikas Rawal
2022-07-07  8:42   ` Jeremie Juste
2022-07-07 12:09     ` Naresh Gurbuxani
2022-07-07  6:22 ` Greg Minshall [this message]

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=3043697.1657174955@apollo2.minshall.org \
    --to=minshall@umich.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=naresh_gurbuxani@hotmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).