簡體   English   中英

組織模式:以編程方式向表頭添加標頭

[英]org-mode: add a header to a table programmatically

我有一個在組織模式下定義的表:

`#+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 |
`

我想產生下表:

#+caption: Caption of my 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 |

我該怎么做? 這是我嘗試過的(在R中):

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

但是,當然這是行不通的,這是我得到的:

`#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 |`

有什么建議么?

謝謝!

這非常接近。 首先定義這個功能:

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

接下來,使用這種src塊。 我使用python,但它也應在R中工作,您只需要:wrap。 我通過var傳遞了您的數據,如果您在塊中生成數據,則不需要它。

#+BEGIN_SRC python :results value :var data=data :wrap (add-caption "Some really long, uninteresting, caption about data that is in this table.")
data.insert(0, ["", "group 1", "group 2", "group 3"])
data.insert(1, None)
return data
#+END_SRC

這個輸出

#+BEGIN_org
#+caption: Some really long, uninteresting, caption about data that is in this    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

我想它也可以出口。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM