From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id gH6aKsWexmKwoQAAbAwnHQ (envelope-from ) for ; Thu, 07 Jul 2022 10:52:21 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id oNpuKsWexmJFZwEAauVa8A (envelope-from ) for ; Thu, 07 Jul 2022 10:52:21 +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 67AF2262A0 for ; Thu, 7 Jul 2022 10:52:21 +0200 (CEST) Received: from localhost ([::1]:47368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9NFD-000516-I3 for larch@yhetil.org; Thu, 07 Jul 2022 04:52:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9N5S-0006Me-F0 for emacs-orgmode@gnu.org; Thu, 07 Jul 2022 04:42:14 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:55219) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o9N5M-0003m8-ME for emacs-orgmode@gnu.org; Thu, 07 Jul 2022 04:42:14 -0400 Received: by mail-wm1-x336.google.com with SMTP id n185so10191557wmn.4 for ; Thu, 07 Jul 2022 01:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=iehY6USQ42aN93OSe/IXXBE9iCzS1Np6WTp6Cs8FuVc=; b=blPv0O8aPUTi0hYinrra7ahYMNI7YFICKArsC9r+L2x4KnaNNIZCLETpiucOtwaakF fVSPJwis6h6uQuJqGIJe5kWr5+zuemoj4n+lDOhnVGzpdbL/9SrGrIfvP7CuGVF7D4H2 m+kmQVHi8y12QERca5mjaLVMW42/FMroyTPSAYdg+mBQG/e69G06fXgYzrdawukjb0B1 /wqOeQnN1YTYXMizLrjfGrtcFATlcI21cE/M81ezI7IyDpz/BcW6yWG0Ymi/f3/SA9sC 4QPpegPzf+JbrwS6iknPBPx+I0fT9bGnARRc31hCfgNrdqfaMQqbP5a+7eXAU2areFN8 IYyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=iehY6USQ42aN93OSe/IXXBE9iCzS1Np6WTp6Cs8FuVc=; b=6eTFQCTPulclqDb7+r8DUepuLGQevxsrxFEXvHvmtg7CASt8vaeZr8F+uB9S64noEV bqCP1SqEtPtWXRoDR8ZmKQcR1sVLu56D3S2rdqelxsLEjz7liEKh6Im9tCscZhYCM4f4 wGLgCC4kBtGBfU3lIcnWvhIX0Q12lytSYinA6G1AaSUCJq7gsgnmA6kDAPe2je6UB97W AN4vGD/RksGOaYahu5cO3eEOzWkys1hdVxAfbLckjW90zfLXQ78COzgxd3s3j/EDQdjY Oi5p1x3DI9drv4rXsdvuP8SUXcjGALajPUnHff317tUWGzHR5bsUBLSkFDh0K3YwOj0j lqTA== X-Gm-Message-State: AJIora8NpuaB9aCY26vhfaNrpk//pg1CHIC64g3zbDMxfSItWxAtO5Rk nNzSQXLoUyHPb6Qd581xG3hItJkfrvO9Yw== X-Google-Smtp-Source: AGRyM1vhbUeMOL9OW0E+QEbvK9Bp7/MSKIN6V1pObRpM26zJrtKSRoQqgTLTG3y0fNpbyCShb0jVBA== X-Received: by 2002:a05:600c:3b1d:b0:3a2:60a1:fe30 with SMTP id m29-20020a05600c3b1d00b003a260a1fe30mr3000818wms.193.1657183325586; Thu, 07 Jul 2022 01:42:05 -0700 (PDT) Received: from flexignu ([2a02:908:1d1:72a0:9d40:c137:7f47:31e0]) by smtp.gmail.com with ESMTPSA id a3-20020a056000100300b0021b943a50b3sm38379365wrx.85.2022.07.07.01.42.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 01:42:04 -0700 (PDT) From: Jeremie Juste To: Vikas Rawal Cc: Naresh Gurbuxani , "emacs-orgmode@gnu.org" Subject: Re: Efficiently reuse code in org babel with R References: Date: Thu, 07 Jul 2022 10:42:02 +0200 In-Reply-To: (Vikas Rawal's message of "Thu, 7 Jul 2022 09:45:00 +0530") Message-ID: <871quxiaat.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=jeremiejuste@gmail.com; helo=mail-wm1-x336.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=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=1657183941; 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=iehY6USQ42aN93OSe/IXXBE9iCzS1Np6WTp6Cs8FuVc=; b=HtepqnB4c5SCWBLEmeHGmK6QkJkXJF507xSezbjoRFxnW1ae1h3MIBERwmtPMPrOc2h5mf zBj6ObAr1/i1Q7cr1Uz1qL376qGc4W7iG/Or3yzAeKnTIyQQTklVNDzQ07c5tEwy4L8e6H nr61ka4oluH7m17VjW5iQGSa2upFoKGayoR6ijZDFUPtG7bg/z2/xivnzIJ0Wlf0/GUoL6 1TDWwfZUzcxlJVXGxmV0t5A5BSq0v2fj27lhVNjr3sjpvzEoCoxEIC79td1ze5LTFZkZCX JyVW9Kkh6ans3jcnUW6Ljpol2hW2tGL/QVF6Zp7eApmkWvJMwQnJdkl0ZfUPtg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1657183941; a=rsa-sha256; cv=none; b=CAprw+LJ2jZlS2PO2IAlKtGejn9gg4UwpAvn4R2HIz+9p6VgJrxmJIzqq4TkmRe4PJ1NaS c1aBJHqAPjjnPx2gYTXSg84RFD7iUgFxpfIr9mv5gzNaozkqkUsSYj/qlPk7gKqcFdYkEQ 4cS5Hi0RneYX1qRxQOc2WVxw6VlyxRf5bpXn/FgbBYchLCOBuu05SQrrJx8Xcs+RHDcQp9 piPW7QDUUAQDeAJxIKBoTpq1hHHCkp+tRAeJe3mCx4aTTMQclKsKONwdzFNUv7VTYXXO5W Svgoqb7KO2LE3PzDgUu+dkMElVZbQRBDoR5GMK2sBFNIaJAqLZdIpWsiH0Nt/w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=blPv0O8a; 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: -9.25 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=blPv0O8a; 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: 67AF2262A0 X-Spam-Score: -9.25 X-Migadu-Scanner: scn0.migadu.com X-TUID: 60LI9+7KN7id Hello Naresh, Many thanks for sharing. If I'm looking for efficiency, I tend not to use noweb and use an R session instead. One reason is that caching does not work with noweb #+name: test #+begin_src R :cache yes :session *R* Sys.sleep(10) a <- 1 #+end_src #+RESULTS[36c41617bf9aa447ecc28fca8207eab38340d418]: test : 1 #+name: add1 #+begin_src R :noweb yes :cache no :session *R* <> a + 1 #+end_src #+RESULTS: add1 : 2 I would proceed in the following way #+name: connection #+begin_src R :exports results :results output :session *R* ## my code here #+end_src #+begin_src R :exports results :results output graphics file :session *R* :file figures/fig1.png ## my code here #+end_src #+begin_src R :exports results output graphics file :file figures/fig2.png :session *R* ## my code here #+end_src this will require running the first code chunk once only to run the rest On Thursday, 7 Jul 2022 at 09:22, Greg Minshall wrote: > 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.) The comment of Greg is very relevant here as you'll have to manage updates yourself, and it can get complex very quickly. A potential pitfall is when the tables in database you are referring to, change. So in this case I would avoid using :cache yes in the first code chunk I'm also tempted to adopt the following organization * setup table #+name: connection #+begin_src R :exports results :results output :session *R* ## my code here #+end_src * output graphs :PROPERTIES: :header-args:R: :exports results output graphics file :session *R* :END: #+begin_src R :file figures/fig2.png ## my code here #+end_src #+begin_src R :file figures/fig1.png ## my code here #+end_src then I would use (org-babel-execute-subtree) which is bound to C-c C-v s on the subheading output graphs to regenerate the graphs. HTH, Jeremie