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

Reply via email to