pander泛型函数忽略参数

问题描述 投票:0回答:1

如果我没错,有两种方法可以使用pander包创建markdown表:使用pandoc.table()函数或泛型函数pander()。但是使用pander()函数,似乎你不能使用pandoc.table()中的参数

例如 :

library(pander)
data(iris)
pandoc.table(summary(iris), split.table="Inf")
pander(summary(iris), split.table="Inf")

使用pandoc.table,由于参数split.table(这是预期的行为),表不会被拆分。但是对于pander,这个论点被忽略了。 我在函数的代码中看到...参数存在于pander.data.frame中,但未在其中重新指定。 :

> pander:::pander.data.frame
function (x, caption = attr(x, "caption"), ...)
{
    if (is.null(caption) & !is.null(storage$caption))
        caption <- get.caption()
    pandoc.table(x, caption = caption)
}

为什么不在函数内重用...参数以允许从pander传递参数到pandoc.table(如下所示)?当然,这可能是一个很好的理由......

function (x, caption = attr(x, "caption"), ...)
{
    if (is.null(caption) & !is.null(storage$caption))
        caption <- get.caption()
    pandoc.table(x, caption = caption,...)
}
r pander
1个回答
2
投票

虽然通过pandoc.table方法处理pander参数是一个合理的想法(我肯定会在下一个版本中允许这个解决方案,感谢这个问题!),这也可以通过一般的pander options更全面地解决。例如。:

> library(pander)
> data(iris)
> panderOptions('table.split.table', 'Inf')
> pander(head(iris))

-------------------------------------------------------------------
 Sepal.Length   Sepal.Width   Petal.Length   Petal.Width   Species 
-------------- ------------- -------------- ------------- ---------
     5.1            3.5           1.4            0.2       setosa  

     4.9             3            1.4            0.2       setosa  

     4.7            3.2           1.3            0.2       setosa  

     4.6            3.1           1.5            0.2       setosa  

      5             3.6           1.4            0.2       setosa  

     5.4            3.9           1.7            0.4       setosa  
-------------------------------------------------------------------

更新[2013/06/11]:recent commit解决了这个问题,现在你可以通过pandoc.table S3方法将这些额外的参数传递给pander

> pander(summary(iris), split.table="Inf")

------------------------------------------------------------------------------
&nbsp;  Sepal.Length   Sepal.Width   Petal.Length   Petal.Width     Species   
------ -------------- ------------- -------------- ------------- -------------
 ****   Min.  :4.300  Min.  :2.000   Min.  :1.000  Min.  :0.100   setosa :50  

 ****  1st Qu.:5.100  1st Qu.:2.800 1st Qu.:1.600  1st Qu.:0.300 versicolor:50

 ****  Median :5.800  Median :3.000 Median :4.350  Median :1.300 virginica :50

 ****   Mean :5.843    Mean :3.057   Mean :3.758    Mean :1.199               

 ****  3rd Qu.:6.400  3rd Qu.:3.300 3rd Qu.:5.100  3rd Qu.:1.800              

 ****   Max.  :7.900  Max.  :4.400   Max.  :6.900  Max.  :2.500               
------------------------------------------------------------------------------
© www.soinside.com 2019 - 2024. All rights reserved.