From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: [babel] apply #+TABLEFM lines during export? Date: Sun, 11 Jul 2010 15:26:30 -0700 Message-ID: <87hbk5mh9j.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=48075 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OYB2c-0004ee-A0 for emacs-orgmode@gnu.org; Mon, 12 Jul 2010 00:54:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OYB2b-0004Vc-7C for emacs-orgmode@gnu.org; Mon, 12 Jul 2010 00:54:54 -0400 Received: from mail-pw0-f41.google.com ([209.85.160.41]:61271) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OYB2b-0004VT-2p for emacs-orgmode@gnu.org; Mon, 12 Jul 2010 00:54:53 -0400 Received: by pwi8 with SMTP id 8so4139805pwi.0 for ; Sun, 11 Jul 2010 21:54:51 -0700 (PDT) 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: Austin Frank Cc: emacs-orgmode@gnu.org Hi Austin, Austin Frank writes: > Hi all-- > > I have a (hopefully quick question) about formatting tabular output from > ob-R. Consider the following block: > > #+source: anova-example > #+BEGIN_SRC R :cache yes :exports results :colnames yes :results value > library(ez) > library(lme4) > > eza <- ezANOVA(dv = .(Reaction), > sid = .(Subject), > within = .(Days), > data = sleepstudy) > > print(eza$ANOVA) > #+END_SRC > > This produces the following output: > #+results[7e7015e41d95ed8986fb9a211a8b5c6e121ae99d]: anova-example > | Effect | DFn | DFd | SSn | SSd | F | p | p<.05 | pes | > |--------+-----+-----+-----------------+------------------+------------------+----------------------+-------+------------------| > | Days | 9 | 153 | 166235.12250176 | 151101.038615303 | 18.7026979326383 | 8.99534541600196e-21 | * | 0.52384550792003 | > > That's more precision than I want in export, so I add a formula line to > the results, hoping to change the formatting of the floats. After > hitting C-u C-u C-c C-c in the table, I get the following: > > #+results[7e7015e41d95ed8986fb9a211a8b5c6e121ae99d]: anova-example > | Effect | DFn | DFd | SSn | SSd | F | p | p<.05 | pes | > |--------+-----+-----+-------------+-------------+---------+--------+-------+--------| > | Days | 9 | 153 | 166235.1200 | 151101.0400 | 18.7027 | 0.0000 | * | 0.5238 | > #+TBLFM: $4=$4;%.4f::$5=$5;%.4f::$6=$6;%.4f::$7=$7;%.4f::$9=$9;%.4f > > That's much better! But, if I export this section to LaTeX, the formula > line is not applied and I end up with the full precision in my table. > > \begin{center} > \begin{tabular}{lrrrrrrlr} > Effect & DFn & DFd & SSn & SSd & F & p & p<.05 & pes \\ > \hline > Days & 9 & 153 & 166235.12250176 & 151101.038615303 & 18.7026979326383 & 8.99534541600196e-21 & * & 0.52384550792003 \\ > \end{tabular} > \end{center} > > Is there a way to make sure that the table formula is applied to the > results block during export? Alternatively, is there another way to > reduce the precision of the numbers produced during export? > Under the current setup, I don't know of a way to ensure that the formula will be re-run. This may be a good place for future (post-feature-freeze) functionality. There has also been discussion of adding a header argument for "post-processing" code blocks which could accept the output of the evaluated code block as input -- this might be related. As a work-around, I would suggest the following emacs-lisp code block. Export of this code block will trigger the evaluation of the R code block, and it will then trim the output of said block resulting in the desired table precision. --8<---------------cut here---------------start------------->8--- #+begin_src emacs-lisp :var tab=anova-example :colnames yes :cache yes (mapcar (lambda (row) (mapcar (lambda (cell) (if (numberp cell) (format "%.4f" cell) cell)) row)) tab) #+end_src #+results[16ac354f1e7a65594bb59e252ab221e6a4b10f80]: | Effect | DFn | DFd | SSn | SSd | F | p | p<.05 | pes | |--------+--------+----------+-------------+-------------+---------+----------------------+-------+--------| | Days | 9.0000 | 153.0000 | 166235.1225 | 151101.0386 | 18.7027 | 8.99534541600196e-21 | * | 0.5238 | --8<---------------cut here---------------end--------------->8--- Cheers -- Eric > > Thanks for any help! > /au