Change default alignment in pander (pandoc.table)

ぐ巨炮叔叔 提交于 2019-12-05 04:23:00

Thanks for you kind words and great question. There's a not yet well documented feature in pander, but you can also pass an R function as the default table alignment. Quick demo:

> panderOptions('table.alignment.default',
+     function(df) ifelse(sapply(df, is.numeric), 'right', 'left'))
> pander(data.frame(
+     name          = letters[1:3],
+     size          = 1:3,
+     we.have.dates = Sys.Date() - 1:3
+ ))

-----------------------------
name     size we.have.dates  
------ ------ ---------------
a           1 2014-11-18     

b           2 2014-11-17     

c           3 2014-11-16     
-----------------------------

So the trick here is to define a function which takes only one argument to be analysed, and it returns the vector of column alignment parameters.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!