R中是否有任何函数允许导出HTML表格作为R Markdown或相关编织文档的一部分,并允许对表格边界进行详细控制?
例如,想象一下这样的矩阵:
x <- matrix(c("","M","F","Good","23","17","Bad","4"),nrow=3,byrow=TRUE)
-------- M F --------------- Good 23 17 --------------- Bad 23 4 ---------------
解决方法
您可以尝试我的年轻包,在名为
pander的大量开发中尝试以
pandoc markdown格式打印R对象.
懒惰的例子:
> x <- matrix(c("",byrow=TRUE) > pandoc(x) +------+------+------+ | | M | F | +------+------+------+ | Good | 23 | 17 | +------+------+------+ | Bad | 23 | 4 | +------+------+------+
我正在研究一些函数,导致其他表语法,如“简单表”或“多行表”(参见Pandoc的自述文件).
P. S.:
您还可以使用(尚未记录的)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.
附:第二:你也可以用brew
(像sweave)一个带有Pandoc.brew的文本文件来自动转换你的<%= ...%>标签从内部R对象到Pandoc降价格式.简短的例子(当然这也适用于文件输入,现在我只是酿造一个R字符向量):
> t <- '# Title + + A nice matrix: + + <%=matrix(c("",byrow=TRUE)%> + + Bye-bye!' > > Pandoc.brew(text=t) # Title A nice matrix: +------+------+------+ | | M | F | +------+------+------+ | Good | 23 | 17 | +------+------+------+ | Bad | 23 | 4 | +------+------+------+ Bye-bye!