Domanda

If I'm not wrong, there are two ways to create markdown tables with pander package: either use the pandoc.table() function or the generic function pander(). However with pander() function, it seems that you cannot use the arguments from pandoc.table()

For example :

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

With pandoc.table, the table is not split because of the argument split.table (that's the intended behavior). But with pander, the argument is ignored.
I see in the code of the function that the ... argument is present in pander.data.frame but is not respecified within it. :

> 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)
}

Why not reuse the ... argument inside the function to allow passing arguments from pander to pandoc.table (like below)? There is maybe a good reason for this of course...

function (x, caption = attr(x, "caption"), ...)
{
    if (is.null(caption) & !is.null(storage$caption))
        caption <- get.caption()
    pandoc.table(x, caption = caption,...)
}
È stato utile?

Soluzione

While processing pandoc.table arguments via the pander method is a reasonable idea (and I will definitely allow this solution in the next release, thanks for the question!), this can be also addressed more globally with general pander options. E.g.:

> 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  
-------------------------------------------------------------------

Update [2013/06/11]: a recent commit resolved this issue and now you can pass those extra params to pandoc.table via pander S3 method:

> 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               
------------------------------------------------------------------------------
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top