I am having a bit of trouble with code blocks that produce org tables to be later consumed by other code blocks. For example:
#+NAME: upper_air
#+BEGIN_SRC clojure :results output raw
(clojure.pprint/print-table table)
#+END_SRC
will produce
#+RESULTS: upper_air
| :m | :degree | :meter/second | :degC | :millibar |
|---------+---------+---------------+------------+-----------|
| 1545.0 | 175.0 | 12.36 | 15.400001 | 850.0 |
| 3162.0 | 265.0 | 6.69 | 4.8 | 700.0 |
but what I would really like is
#+TBLNAME: upper_air
| :m | :degree | :meter/second | :degC | :millibar |
|---------+---------+---------------+------------+-----------|
| 1545.0 | 175.0 | 12.36 | 15.400001 | 850.0 |
| 3162.0 | 265.0 | 6.69 | 4.8 | 700.0 |
(note #+RESULTS
vs. #+TBLNAME
) so that subsequently I can do something like
#+BEGIN_SRC ipython :session :var data=upper_air
import numpy as np
arr = np.array(data)
p = arr[:,4]
#+END_SRC
With the #+RESULTS
result, the second code block will interpret the data
argument as a string instead of a data table and I will not be able to extract
the data in a straightforward way. I could convert the ASCII data to a Python data structure 'manually', but I would prefer org handle it for me :-) Is there a way for either the first code block to output a #+TBLNAME
instead of #+RESULTS
? Alternatively, can the second code block coerce the argument as an
org table instead of a string?
clojure.pprint/print-table
returns a string formatted as Org table, and since you set header argument to beoutput
andraw
, you get what you get. However, when you use it second time, Org doesn't read the resulting table, instead, it re-evaluates the Clojure block and feeds its result to the Python block. However, if the Clojure block produced a 2D array, you could change the result to bevalue
and notraw
for Org to format that result as a table, and you would get it as a 2D array in Python block.