6

I'm trying to send an Org table as a lisp object to a code block for further processing with an elisp function. For testing I set up two code blocks, one that generates the table and another that receives the table.

The first block works fine:

#+NAME: from-r
#+BEGIN_SRC R :results value :colnames yes
  q <- data.frame(something1 = c("a", "b", "c"), something2 = c(1, 5, 100))
  q
#+END_SRC

#+RESULTS: from-r
| something1 | something2 |
|------------+------------|
| a          |          1 |
| b          |          5 |
| c          |        100 |

But the second block is not receiving the whole table!

#+BEGIN_SRC emacs-lisp :var the-table=from-r :results output
  (print the-table)
#+END_SRC

#+RESULTS:
: 
: (("a" 1) ("b" 5) ("c" 100))

Looking at the messages buffer...

executing R code block (from-r)...
Wrote /tmp/babel-1755OIV/ob-input-17558YA
(("something1" "something2") hline ("a" 1) ("b" 5) ("c" 100))
executing Emacs-Lisp code block...

(the-table (quote (("a" 1) ("b" 5) ("c" 100))))

Code block evaluation complete.

...it's clear to me that the output of the 1st block is the complete table but the second block somehow removes the table header. For clarity:

Complete table: (("something1" "something2") hline ("a" 1) ("b" 5) ("c" 100))

Table w/o header: (("a" 1) ("b" 5) ("c" 100))

I'm I missing something?

8

You need to add :colnames no to the second code block. (Org uses org-babel-disassemble-tables to take apart a table and this function uses :colnames to decide if it needs to strip column names.)

Add :hlines yes to keep hline too.

I don't have R installed, but this seems to work:

#+name: make-table
#+BEGIN_SRC elisp :results value
'(("something1" "something2") hline ("a" 1) ("b" 5) ("c" 100))
#+END_SRC

#+RESULTS: make-table
| something1 | something2 |
|------------+------------|
| a          |          1 |
| b          |          5 |
| c          |        100 |

#+BEGIN_SRC elisp :var table=make-table :results output :colnames no
(print table)
#+END_SRC

#+RESULTS:
: 
: (("something1" "something2") ("a" 1) ("b" 5) ("c" 100))

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.