3

I'm using org-babel to generate a result I want to export in my table. However I can't find a way to easily control the heading of the table. At the moment the best I can manage is echo'ing some CSV data in my SRC. For example:

#+name: size-of-tcg
#+BEGIN_SRC sh :dir ~/lsrc/qemu/qemu.git/ :results output table :exports results
EXCL_SPEC='-and -not -iname "kvm*" -and -not -iname "gdb*" -and -not -iname "machine.c"'
echo "arch, language, lines of code"
eval find target-i386/ -xtype f ${EXCL_SPEC} > /tmp/cloc-files
cloc --quiet --csv --list-file=/tmp/cloc-files | tail -n +3 | cut -d"," -f2,5 | sed s/^/i386,/
eval find target-sparc/ -xtype f ${EXCL_SPEC} > /tmp/cloc-files
cloc --quiet --csv --list-file=/tmp/cloc-files | tail -n +3 | cut -d"," -f2,5 | sed s/^/ppc,/
eval find target-arm/ -xtype f ${EXCL_SPEC} > /tmp/cloc-files
cloc --quiet --csv --list-file=/tmp/cloc-files | tail -n +3 | cut -d"," -f2,5 | sed s/^/arm,/
echo " , Total, "
#+END_SRC
#+CAPTION: TCG Code for various target-*
#+ATTR_HTML: :border 2 :rules all :frame border :width 90%
#+RESULTS: size-of-tcg
| arch | language     | lines of code |
| i386 | C            |         17032 |
| i386 | C/C++ Header |          4086 |
| ppc  | C            |         10483 |
| ppc  | C/C++ Header |           834 |
| arm  | C            |         28941 |
| arm  | C/C++ Header |          1962 |
|      | Total        |         63338 |
#+TBLFM: @8$3=vsum(@2$3..@7$3)

Is there a better way to do this?

  • Is there anything in particular you'd like to improve in this setup? Your solution seems reasonable at first sight. – Malabarba Oct 7 '14 at 20:08
  • Currently the headings aren't nicely formatted. But as the input is CSV it's hard to add the |-- line for the divider. Also I can't automatically do the totalling. – stsquad Oct 8 '14 at 7:58
  • I think I might need to copy the contents from the #+RESULTS: table to a new non RESULTS table and work there. But I can't find a decent way of doing that. – stsquad Oct 8 '14 at 11:13
1

So the cleanest solution I've come up with so far is to copy the data:

#+name: size-of-tcg
#+BEGIN_SRC sh :dir ~/lsrc/qemu/qemu.git/ :results output table :exports none
EXCL_SPEC='-and -not -iname "kvm*" -and -not -iname "gdb*" -and -not -iname "machine.c"'
eval find target-i386/ -xtype f ${EXCL_SPEC} > /tmp/cloc-files
cloc --quiet --csv --list-file=/tmp/cloc-files | tail -n +3 | cut -d"," -f2,5 | sed s/^/i386,/
eval find target-sparc/ -xtype f ${EXCL_SPEC} > /tmp/cloc-files
cloc --quiet --csv --list-file=/tmp/cloc-files | tail -n +3 | cut -d"," -f2,5 | sed s/^/ppc,/
eval find target-arm/ -xtype f ${EXCL_SPEC} > /tmp/cloc-files
cloc --quiet --csv --list-file=/tmp/cloc-files | tail -n +3 | cut -d"," -f2,5 | sed s/^/arm,/
#+END_SRC
#+NAME: tcg-raw-data
#+RESULTS: size-of-tcg
| i386 | C            | 17032 |
| i386 | C/C++ Header |  4086 |
| ppc  | C            | 10483 |
| ppc  | C/C++ Header |   834 |
| arm  | C            | 28941 |
| arm  | C/C++ Header |  1962 |

#+CAPTION: TCG Code for various target-*
#+ATTR_HTML: :border 2 :rules all :frame border :width 90%
| Architecture | Lines of Code |
|--------------+---------------|
| i386         |         21118 |
| ppc          |         11317 |
| arm          |         30903 |
|--------------+---------------|
| Total        |         63338 |
#+TBLFM: @2$1=remote(tcg-raw-data,@1$1)::@2$2=vsum(remote(tcg-raw-data,@1$3..@2$3))::@3$1=remote(tcg-raw-data,@3$1)::@3$2=vsum(remote(tcg-raw-data,@3$3..@4$3))::@4$1=remote(tcg-raw-data,@5$1)::@4$2=vsum(remote(tcg-raw-data,@5$3..@6$3))::@5$2=vsum(@2..@4)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.