r - org-mode: add a header to a table programmatically -


i have table definied in org-mode:

`#+results[4fc5d440d2954e8355d32d8004cab567f9918a64]: table |  7.4159 | 3.0522 |  5.9452 | | -1.0548 | 12.574 | -6.5001 | |  7.4159 | 3.0522 |  5.9452 | |  5.1884 | 4.9813 |  4.9813 | ` 

and want produce following table:

#+caption: caption of table | | group 1 | group 2 | group 3 | |--------+---------+---------+---------| | plan 1 | 7.416 | 3.052 | 5.945 | | plan 2 | -1.055 | 12.574 | -6.5 | | plan 3 | 7.416 | 3.052 | 5.945 | | plan 4 | 5.1884 | 4.9813 | 4.9813 |

how can accomplish that? here tried (in r):

`  #+begin_src r :colnames yes :var table=table :session   data.frame(table)  #+end_src ` 

but of course doesn't work, here get:

`#results: | x7.4159 | x3.0522 | x5.9452 | |---------+---------+---------| | -1.0548 |  12.574 | -6.5001 | |  7.4159 |  3.0522 |  5.9452 | |  5.1884 |  4.9813 |  4.9813 |` 

any suggestions?

thanks!

this gets pretty close. first define function:

#+begin_src emacs-lisp (defun add-caption (caption)   (concat (format "org\n#+caption: %s" caption))) #+end_src 

next, use kind of src block. use python, should work in r too, need :wrap. passed data in through var, don't need if generate data in block.

#+begin_src python :results value :var data=data :wrap (add-caption "some long, uninteresting, caption data in table.") data.insert(0, ["", "group 1", "group 2", "group 3"]) data.insert(1, none) return data #+end_src 

this outputs

#+begin_org #+caption: long, uninteresting, caption data in    table. |        | group 1 | group 2 | group 3 | |--------+---------+---------+---------| | plan 1 |   7.416 |   3.052 |   5.945 | | plan 2 |  -1.055 |  12.574 |    -6.5 | | plan 3 |   7.416 |   3.052 |   5.945 | | plan 4 |  5.1884 |  4.9813 |  4.9813 | #+end_org 

and exports ok think.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -