您可以尝试我在重度开发下名为 pander 的非常年轻的包,它试图以 pandoc markdown 格式打印 R对象。
懒惰的例子:
> x <- matrix(c("", "M", "F", "Good", "23", "17", "Bad", "23", "4"), nrow=3, byrow=TRUE)
> pandoc(x)
+------+------+------+
| | M | F |
+------+------+------+
| Good | 23 | 17 |
+------+------+------+
| Bad | 23 | 4 |
+------+------+------+
我只是在处理一些导致其他表语法的函数,例如“简单表”或“多行表”(请参阅 Pandoc 的自述文件)。
PS:您还可以使用(尚未记录的)Pandoc
参考类轻松将此表导出为 HTML(除了 docx、odt 等其他格式),例如:
> myReport <- Pandoc$new()
> myReport$add(x)
> myReport
Anonymous's report
==================
written by *Anonymous* at *Sun May 27 21:04:22 2012*
This report holds 1 block(s).
---
+------+------+------+
| | M | F |
+------+------+------+
| Good | 23 | 17 |
+------+------+------+
| Bad | 23 | 4 |
+------+------+------+
---
Proc. time: 0.009 seconds.
> myReport$format <- 'html'
> myReport$export()
Exported to */tmp/pander-4e9c12ff63a6.[md|html]* under 0.031 seconds.
PS第二:您还可以brew
(如编织)一个文本文档,使用该文档将您的标签从内部R对象Pandoc.brew
自动转换为Pandoc markdown格式。<%=...%>
简短的例子(当然这也适用于文件输入,现在我只是brew
一个 R 字符向量):
> t <- '# Title
+
+ A nice matrix:
+
+ <%=matrix(c("", "M", "F", "Good", "23", "17", "Bad", "23", "4"), nrow=3, byrow=TRUE)%>
+
+ Bye-bye!'
>
> Pandoc.brew(text=t)
# Title
A nice matrix:
+------+------+------+
| | M | F |
+------+------+------+
| Good | 23 | 17 |
+------+------+------+
| Bad | 23 | 4 |
+------+------+------+
Bye-bye!