From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id SGzBG0d8xmL5gwAAbAwnHQ (envelope-from ) for ; Thu, 07 Jul 2022 08:25:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id cHKxG0d8xmIZiQAA9RJhRA (envelope-from ) for ; Thu, 07 Jul 2022 08:25:11 +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 993B0302D5 for ; Thu, 7 Jul 2022 08:25:10 +0200 (CEST) Received: from localhost ([::1]:55446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9Kwm-00073T-EG for larch@yhetil.org; Thu, 07 Jul 2022 02:25:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9KuW-000723-Ep for emacs-orgmode@gnu.org; Thu, 07 Jul 2022 02:22:48 -0400 Received: from relay-egress-host.us-east-2.a.mail.umich.edu ([18.216.144.57]:44000 helo=fit-hafgan.relay-egress.a.mail.umich.edu) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o9KuU-0004C8-G7 for emacs-orgmode@gnu.org; Thu, 07 Jul 2022 02:22:48 -0400 Received: from united-wendigo.authn-relay.a.mail.umich.edu (ip-10-0-72-141.us-east-2.compute.internal [10.0.72.141]) by fit-hafgan.relay-egress.a.mail.umich.edu with ESMTPS id 62C67BB1.2C3DE323.35640F38.1395456; Thu, 07 Jul 2022 02:22:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umich.edu; s=relay-2018-08-29; t=1657174961; bh=34QYkq5jJaWLDx7jW8ZmNaV9mrQfc/1y63B7lkg7hGY=; h=To:cc:From:Subject:In-reply-to:References:Date; b=pok5aB+1XFHFe+miSm8V6sst4UUtUQJ8XsgYICQVHGdIdqSEMjPzLXr8AyWPXR7FG beI+C9CbXxdymTNCqhqMn48hlaQZfCpPEC7IkVxTy99byu1tcu4wbO7EL7crCZ4VZX Vsa672nD1mTI8o0HQXHQDlLJ0MB2R4RfyedkAmuPaUNpbQpDYc5wra/8FC8EOr7Izs gHDm7KIpRWfZVyf3/xeEpKi8GNGMiRHj3Y6vDn7auTgTdFbGQvErFznHvdvAg3kZHK L47j1Ww63jalNW1Yna9y0C0QVMmbFyIg+4FnCM5Rpi4axLAbaNXEaPyJ9/P7sNpwps RUStr0vBa9RWw== Received: from localhost (Mismatch [78.179.92.143]) by united-wendigo.authn-relay.a.mail.umich.edu with ESMTPSA id 62C67BAF.3819C94E.2664C71A.1160169; Thu, 07 Jul 2022 02:22:40 -0400 To: Naresh Gurbuxani cc: "emacs-orgmode@gnu.org" From: Greg Minshall Subject: Re: Efficiently reuse code in org babel with R In-reply-to: References: Comments: In-reply-to Naresh Gurbuxani message dated "Thu, 07 Jul 2022 03:31:20 +0000." X-Mailer: MH-E 8.6+git; nmh 1.7.1; GNU Emacs 28.1.50 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3043696.1657174955.1@apollo2.minshall.org> Date: Thu, 07 Jul 2022 09:22:35 +0300 Message-ID: <3043697.1657174955@apollo2.minshall.org> Received-SPF: pass client-ip=18.216.144.57; envelope-from=minshall@umich.edu; helo=fit-hafgan.relay-egress.a.mail.umich.edu 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, 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=1657175111; 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=34QYkq5jJaWLDx7jW8ZmNaV9mrQfc/1y63B7lkg7hGY=; b=iLQPnVZ9V3E2yHeajdUOOPgP1v+zdcvZL0Q8Xpw4vmSzTznEkQsl/n+I1F7sc4ccS/oDiN FcMGpVgPCK7U775nHcIJo1BOVCU9Q/xG8BUYM0Bs/ezxf0CiIvmw+fwgp81CfNAzQrZBcG SHVGTGmV33kLw4c0WFRdXPCXAIFJ1gn0Nk6ib0HujkcSaoAmAPXkM00Id5nlL9Yy4TPvoI xOoOBfuqckISklfClnc7lfKdPfX7xmUmEL2OhnV0f5ph1UroKf/micMLgACOGZf17l1OpE JKrM7/QLkJRh29Fk7UdCt5/EFWvdMo8vfQH/NWakHJeL4aejoYsk6U+ItwKi/Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1657175111; a=rsa-sha256; cv=none; b=nPxUuY7gMNITlvF43z5J0KArm0jtCLBM9iXJ5aO0PSF68+XnMZXeBDRLQq/SNrQqh431T1 fZGNwAJ7neHyOxgQjhI31JgKj7tMtImPEjWY9qzmBm72MDATgtjp+Aci2JoBQMtK8RQl1P ChSpBt4byocOAZ1bv00Ivhuz+0vhtwkn/9E1G7AbtKAG1ukMx1SR29avN1nO9ZYfjvKL1Z AVsCqHm2s3Pgxkj21IUjWUdcbrrmTtf9HBC5smcywNXF/eTbaMxlrWnk+sq3fj23r6Sd+E d1YhgxnAr1bJmyysOylrX9v38hW8dtk7dgsart+tozN1qTJ4Mkn+zmI0bwFoKA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=umich.edu header.s=relay-2018-08-29 header.b=pok5aB+1; dmarc=pass (policy=none) header.from=umich.edu; 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: -8.95 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=umich.edu header.s=relay-2018-08-29 header.b=pok5aB+1; dmarc=pass (policy=none) header.from=umich.edu; 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: 993B0302D5 X-Spam-Score: -8.95 X-Migadu-Scanner: scn0.migadu.com X-TUID: 7G2Ey9BHQXxP 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 =<>), 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