From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Bogner Subject: formatting org-babel output Date: Wed, 22 May 2013 07:18:40 -0400 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:39953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uf749-0004zN-Bc for emacs-orgmode@gnu.org; Wed, 22 May 2013 07:18:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uf745-0006Ym-D0 for emacs-orgmode@gnu.org; Wed, 22 May 2013 07:18:45 -0400 Received: from mail-ve0-x22e.google.com ([2607:f8b0:400c:c01::22e]:54783) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uf745-0006Yc-6W for emacs-orgmode@gnu.org; Wed, 22 May 2013 07:18:41 -0400 Received: by mail-ve0-f174.google.com with SMTP id oy12so1326201veb.5 for ; Wed, 22 May 2013 04:18:40 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org I am using org-mode and babel with R for reproducible research. I would like certain numbers in the output tables to be formatted for easier reading - such as eliminating decimals and adding commas for readability. The best I came up with is to use a TBLFM line at the bottom of my results table using a function I found on the ElispCookbook on emacswiki. A simple example is below that doesn't require R to reproduce. It's a two step process currently to execute the R code in org-babel and then jump to the result table TBLFM line and Ctrl+c Ctrl+c to format the table Is there a better way to format table outputs for simple things like currency? I would be content if it's only during the org export process too #+BEGIN_SRC emacs-lisp (defun group-number (num &optional size char) "Format NUM as string grouped to SIZE with CHAR." ; Based on code for `math-group-float' in calc-ext.el (let* ((size (or size 3)) (char (or char ",")) (str (if (stringp num) (number-to-string (string-to-number (replace-regexp-in-string "," "" num))) (number-to-string num))) (pt (or (string-match "[^0-9a-zA-Z]" str) (length str)))) (while (> pt size) (setq str (concat (substring str 0 (- pt size)) char (substring str (- pt size))) pt (- pt size))) str)) #+END_SRC #+RESULTS: : group-number #+NAME: example-table | 100000000.55 | a | | 23000 | b | | 3000 | c | | 40004 | e | | 5000 | 3 | This is the table I want formatted #+BEGIN_SRC emacs-lisp :var data=example-table data #+END_SRC #+RESULTS: | 100,000,000.55 | a | | 23,000 | b | | 3,000 | c | | 40,004 | e | | 5,000 | 3 | #+TBLFM: $1='(group-number $1)'