更改Pander中的默认对齐方式(pandoc.table) [英] Change default alignment in pander (pandoc.table)

查看:128
本文介绍了更改Pander中的默认对齐方式(pandoc.table)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于大多数knitr-markdown格式,我目前都切换到pander,因为它提供了如此强大的pandoc支持.我不满意的一件事是默认的中心对齐.营销人员可能会喜欢它,但是对于技术报告来说,这是一种恐怖.

I am currently switching to pander for most of my knitr-markdown formatting, because it provides such great pandoc support. One of the things I am not so happy with is the default center-alignment. Marketing people may love it, but for technical reports it is an horror.

Hmisc使用的最佳选择是默认情况下对文本和日期使用左对齐,对所有类型的数字使用右对齐.

The best choice used by Hmisc is to use left alignment for texts and dates by default, and right alignment for number of all type.

是否有一种简单的方法可以在pander中进行全局设置?

Is there a simple way to get this globally set in pander?

library(pander)
pander(data.frame(
     name          = letters[1:3],
     size          = 1:3,
     we.have.dates = Sys.Date() - 1:3
 ))

推荐答案

感谢您的客气话和很好的提问. pander中尚没有一个文档完善的功能,但您也可以将R函数作为默认表格对齐方式.快速演示:

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.

这篇关于更改Pander中的默认对齐方式(pandoc.table)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆