From mboxrd@z Thu Jan 1 00:00:00 1970 From: Erik Iverson Subject: [babel] silent code block evaluation on export Date: Tue, 31 Aug 2010 13:42:26 -0500 Message-ID: <4C7D4D12.1070002@ccbr.umn.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=45594 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OqVn3-0006dn-Fg for emacs-orgmode@gnu.org; Tue, 31 Aug 2010 14:42:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OqVmy-0008Gv-7C for emacs-orgmode@gnu.org; Tue, 31 Aug 2010 14:42:37 -0400 Received: from walleye.ccbr.umn.edu ([128.101.116.11]:3501) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OqVmy-0008Gj-0m for emacs-orgmode@gnu.org; Tue, 31 Aug 2010 14:42:32 -0400 Received: from tadpole.ccbr.umn.edu (tadpole.ccbr.umn.edu [128.101.116.26]) by walleye.ccbr.umn.edu (8.9.3p2/8.9.3) with ESMTP id NAA28790 for ; Tue, 31 Aug 2010 13:42:29 -0500 (CDT) Received: from iron.ccbr.umn.edu (iron.ccbr.umn.edu [128.101.116.194]) by tadpole.ccbr.umn.edu (8.9.3/8.9.3) with ESMTP id NAA29204 for ; Tue, 31 Aug 2010 13:42:27 -0500 (CDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode Hello! I have pasted an org-mode file with my question, it's easies to explain by copying the below file and exporting it to HTML. Thanks, --Erik ---------------------------------------------------------------- * Silent code block evaluation on export. The goal is to /run/ a code block on export for some side effect, without any evidence in the exported file that this happened. For example, loading some R package, reading in a dataset, or setting R options. All this is presumably done with :session in mind, even though I don't use it here. In Sweave, we can specify the code block options echo = FALSE, results = hide to faciliate this. However, there are no command line arguments alone in org-mode that can replicate such behavior. Below are several examples and how they fail. There is also an example of a 'trick' that does work to generate the output (or lack thereof) that we want. /:results value/ tries to coerce its return value to a data.frame, so when I reference 'non-conformable object' below, I mean something for which the as.data.frame function generates an error. * /:results value/ (the default for code blocks) ** with a simple object on the last line, a vector This prints the return object, OK. /:exports results :results value/ #+begin_src R :exports results :results value 2 + 2 #+end_src ** with a non-conformable object as the final value This produces an error, as expected, and no output is produced, but only by accident. /:exports results :results value/ #+begin_src R :exports results :results value summary(lm(1 ~ 1)) #+end_src ** using NULL as the last line This does what we want, but requires a 'trick'. OK. /:exports results :results value/ #+begin_src R :exports results :results value summary(lm(1 ~ 1)) NULL #+end_src * /:results silent/ ** with a simple object on the last line, a vector This still prints the return object, it may be debateable if it should. The combination of /:exports results/ and /:results silent/ does not seem inherently self-contradictory. /:exports results :results silent/ #+begin_src R :exports results :results silent 2 + 2 #+end_src ** with a non-conformable object as the final value However, with a non-conformable object on last line, an error is produced when the code is evaluated in the buffer. I'm wondering if /:results silent/ is specified, why the cast to data.frame is occurring? It could be happening for good reason that I'm not aware of. The lack of output here is due to an error occurring. /:exports results :results silent/ #+begin_src R :exports results :results silent summary(lm(1 ~ 1)) #+end_src ** using NULL as the last line This does as we want, using the NULL trick. /:exports results :results silent/ #+begin_src R :exports results :results silent summary(lm(1 ~ 1)) NULL #+end_src * Ideas Since the NULL trick is R-only, how could we specify command line options to faciliate this use case? Possible solutions: 0) There already exists a solution that I don't list here. 1) Make /:exports results :results silent/ do it, but note the results above with a non-conformable object! 2) Make /:exports none/ still evaluate the code block on export. Probably counter-intuitive. 3) Make export use the /:eval/ argument combined with /:exports/, maybe something like: /:exports none :eval yes/ 4) Another better solution!