From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id +HgaOPJfxmIJvgAAbAwnHQ (envelope-from ) for ; Thu, 07 Jul 2022 06:24:18 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id QI3rN/JfxmLM0AAAauVa8A (envelope-from ) for ; Thu, 07 Jul 2022 06:24:18 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 92A7F7D18 for ; Thu, 7 Jul 2022 06:24:18 +0200 (CEST) Received: from localhost ([::1]:33508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9J3p-0001YT-Er for larch@yhetil.org; Thu, 07 Jul 2022 00:24:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9Iv5-0003pf-N6 for emacs-orgmode@gnu.org; Thu, 07 Jul 2022 00:15:18 -0400 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]:33348) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o9Iv3-00045X-WF for emacs-orgmode@gnu.org; Thu, 07 Jul 2022 00:15:15 -0400 Received: by mail-il1-x134.google.com with SMTP id p13so10384028ilq.0 for ; Wed, 06 Jul 2022 21:15:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wPfGwFooGP5gG2i0nlCEH9jLfkgI6NyhvmXaSWXb19g=; b=VD9Go5m6KuaVXytPYMdlwgwmlQ1jSahod0/vDA3F94QBd/5zEw9wnm7qMriAJkdWM5 QFgr9eqO9OLLGZpzGJq8bbFi7/Px6GvmXLutSJw9wmvaU6avC5TYWcWhtiwR59JNAlSE yD8pfGbYic20RYklvPMGBLOgYwZcNMWgDPhegDSS7NYKiXhXdlNcgwZQHXBTfQ5WIQ5B ck47kwJUoeCf7WkFhwD1RU4RV8WfrmcN9R0NJmaulObIXGHBpGN9gOQHb06jMFK0KCuL dRn6j1I7W1CMvHelq0Wuf+bb2tZ6FrSUIKCmkHKjaSbXfPm43F8GawsjldUdOmVYhc1o qsyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wPfGwFooGP5gG2i0nlCEH9jLfkgI6NyhvmXaSWXb19g=; b=pOn41R77NyxPuGqlZf+TwJ2sl6eZEUizwUAqkQhKgpEXzo91k5kMo9Xh8bOFKhEWvA jZ/MaDbFJ7kYvcDyI1wkUrOXAyFT3c7maB2AFeQGetd6sRs8hvhUyrBaogUDjVqDe8vF 1G4Un9PHrRtkfT0a4YNuTbtC07N4XqoClhu4+4egv4CizeVsKiD/MdfcvmCsNvVTJXrR KHNz5C0I9jmYy3il0EjxwhFOHeVcQDlxFLoQN52t0Ku7DuzPr8zn3Ahq7k8fxdvqAey6 pqK+EIaB1jk1RF3+1+u2LnJrkQdKwKiCC6+cKaU8STgU1/nNKOUrBiS1fxyy5WDpVabf hqWA== X-Gm-Message-State: AJIora+t+oIomwyD1/uXfn404NlwKaJ02vcIE8Z+qM1bNF3g17XxllIX DC0GEqz/awdcUhm9xNTWCjB2S87KfknGGh20IVk= X-Google-Smtp-Source: AGRyM1tEHAohpf4kiaynYWxgJr6QQMvIU9VpyXqa2Z2Y/YfXJQ7qVzTKvDDbFvvwpCPI/kcXVVHILw5JvLBE0rgYIUE= X-Received: by 2002:a92:d409:0:b0:2dc:40d:169 with SMTP id q9-20020a92d409000000b002dc040d0169mr14627968ilm.135.1657167311690; Wed, 06 Jul 2022 21:15:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Vikas Rawal Date: Thu, 7 Jul 2022 09:45:00 +0530 Message-ID: Subject: Re: Efficiently reuse code in org babel with R To: Naresh Gurbuxani Cc: "emacs-orgmode@gnu.org" Content-Type: multipart/alternative; boundary="000000000000f260bf05e32f54ef" Received-SPF: pass client-ip=2607:f8b0:4864:20::134; envelope-from=vikasrawal@gmail.com; helo=mail-il1-x134.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1657167858; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=wPfGwFooGP5gG2i0nlCEH9jLfkgI6NyhvmXaSWXb19g=; b=eHCmrnOq1GCcxPJ4JKhToiOKgWiRUC4VpM0PJduaMUOzO5GmO9i0CjTLqKV3WbjCO263W5 k4PaQ5d8U1d/IubKDcZYWR6GtQsYLUh8pBtYSuKlcQj6djX5SBqqfIYqFBBVRWCyaTBJ7O kNGy9A9QDDJAFqifN3T33r8s/4Yjr1CirDzsyow7k82746CxUsRfoMi+URrNaWF0Ijvyvd 3F8zti9YMZ7IW04shULwkmixNw16rG/HqYpU3vW78NSwYflXD+WX22u+as44EHq9NnSJ9n JQkkffByQdUAODjatTEEwOADL5dbTg0hpdNcbQwg/ulwNFuENcj56mNoaALAkA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1657167858; a=rsa-sha256; cv=none; b=D2pnce/MNRzIzPdRzsAf/afJgHLe7C6yvb1ji8yEDgfN19009fvSM6NT5/dC0MSkWeaCPv vZ3ezK4fGbdkhcduwn/yxpysF6AUSaH/v0d47TBiFjxsd5gYHwpQgJRaxpM+CGd/AxEIsK /m+nmZotGDFrjSEjXP8+EZoOZe+pHUolQczlzJZRsTqF/kwXs00A1ZtR+Pa8U+budOq5nM TdZBKwq65JJodOjlp9LpS8rsxjJqkrGC5upf2b2fL8Qz+r+vKIoHMBEpCgsbDBdaHKbfgF e3/G3IHkXByt+QdTi0G0O/MPfiZkP58YdXGqlv6P9OtbFgapHNVTARLiRdlZEw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=VD9Go5m6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.94 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=VD9Go5m6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 92A7F7D18 X-Spam-Score: -3.94 X-Migadu-Scanner: scn1.migadu.com X-TUID: iBJWDC3qZgeb --000000000000f260bf05e32f54ef Content-Type: text/plain; charset="UTF-8" Why not specify a :session so that data created by one block would remain available to subsequent blocks? V. On Thu, 7 Jul 2022 at 09:10, Naresh Gurbuxani wrote: > 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? > > Thanks, > Naresh > > #+name: connection > #+begin_src R :exports results :results output > ## my code here > #+end_src > > #+begin_src R :exports results :results output graphics file :file > figures/fig1.png > <> > ## my code here > #+end_src > > #+begin_src R :exports results output graphics file :file figures/fig2.png > <> > ## my code here > #+end_src > --000000000000f260bf05e32f54ef Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Why not specify a :session so that data created by one blo= ck would remain available to subsequent blocks?

V.
=

= On Thu, 7 Jul 2022 at 09:10, Naresh Gurbuxani <naresh_gurbuxani@hotmail.com> wrote:
I want to source some da= ta from databases, then use this data in various blocks.=C2=A0 I am looking= for the most efficient way to achieve this.=C2=A0 In below blocks, is the = code in block ``connection'' executed thrice (economy of code but n= o saving of time) or is it only executed once then used twice?=C2=A0 If the= code is run thrice, is there another way to create code blocks so that the= code is executed only once?

Thanks,
Naresh

#+name: connection
#+begin_src R :exports results :results output
=C2=A0 ## my code here
#+end_src

#+begin_src R :exports results :results output graphics file :file figures/= fig1.png
<<connection>>
## my code here
#+end_src

#+begin_src R :exports results output graphics file :file figures/fig2.png<= br> <<connection>>
## my code here
#+end_src
--000000000000f260bf05e32f54ef--