Kable function: "id" in columns

When I try to print a table with the knitr::kableid function of the word apperas in the column names. How can I change it?

Example:

> x <- structure(c(42.3076923076923, 53.8461538461538, 96.1538461538462,
                   2.56410256410256, 1.28205128205128, 3.84615384615385,
                   44.8717948717949, 55.1282051282051, 100),
                 .Dim = c(3L, 3L),
                 .Dimnames = structure(list(Condition1 = c("Yes", "No", "Sum"),
                                            Condition2 = c("Yes", "No", "Sum")),
                 .Names = c("Condition1", "Condition2")), class = c("table", "matrix"))
> print(x)
          Condition2
Condition1    Yes     No    Sum
       Yes  42,31   2,56  44,87
       No   53,85   1,28  55,13
       Sum  96,15   3,85 100,00
> library(knitr)
> kable(x)
|id   |   Yes|    No|    Sum|
|:----|-----:|-----:|------:|
|Yes  |  42,3|  2,56|   44,9|
|No   |  53,8|  1,28|   55,1|
|Sum  |  96,2|  3,85|  100,0|

Change . I found the reason for this behavior in a function knitr:::kable_mark. But now I don’t understand how to make it more flexible.

+4
source share
2 answers

I think the easiest way is to pry and completely replace kable_mark. Note: this is pretty dirty, but it seems to work, and there is no way to set it up kable_mark(you could send a patch for knitr, though).

km <- edit(knitr:::kable_mark)
# Now edit the code and remove lines 7 and 8.

unlockBinding('kable_mark', environment(knitr:::kable_mark))
assign('kable_mark', km, envir=environment(knitr:::kable_mark))

: .

if (grepl("^\\s*$", cn[1L])) 
    cn[1L] = "id"

... , , , .

unlockBinding, knitr:::kable_mark . , assign .

, knitr:::kable_mark. .

+1

kable S3 pander:

> library(pander)
> pander(x, style = 'rmarkdown')


|  &nbsp;   |  Yes  |  No   |  Sum  |
|:---------:|:-----:|:-----:|:-----:|
|  **Yes**  | 42.31 | 2.564 | 44.87 |
|  **No**   | 53.85 | 1.282 | 55.13 |
|  **Sum**  | 96.15 | 3.846 | 100   |

, R:

> panderOptions('decimal.mark', ',')
> pander(x, style = 'rmarkdown')


|  &nbsp;   |  Yes  |  No   |  Sum  |
|:---------:|:-----:|:-----:|:-----:|
|  **Yes**  | 42,31 | 2,564 | 44,87 |
|  **No**   | 53,85 | 1,282 | 55,13 |
|  **Sum**  | 96,15 | 3,846 | 100   |

: http://rapporter.imtqy.com/pander/#pander-options

+2

All Articles