rknitrr-markdownpandocpander

pander markdown tables with pipes inside not processed correctly


I generate markdown tables with pander R package that have pipes in some column titles (like : P > |t| ). It seems (unless I missed something) that they are not correctly processed neither by pandoc nor by Rmarkdown due to the confusion between column separators and "true" pipes.

Consider the following Rmd example:

```{r  message = FALSE}
library(pander)
panderOptions("table.style" , "rmarkdown")
panderOptions("table.split.table" , Inf) # avoid to split the tables

data(iris)
mod <- lm(Sepal.Length ~ Species, data = iris)
```

```{r results='asis'}
pandoc.table(summary(mod)$coefficients[,-4])
```

```{r results='asis'}
pandoc.table(summary(mod)$coefficients)
```

The last table generated by pander looks like this (note the pipes in the last column name):

|                  &nbsp; |  Estimate  |  Std. Error  |  t value  |  Pr(>|t|)  |
|------------------------:|:----------:|:------------:|:---------:|:----------:|
|         **(Intercept)** |   5.006    |    0.0728    |   68.76   | 1.134e-113 |
|   **Speciesversicolor** |    0.93    |    0.103     |   9.033   |  8.77e-16  |
|    **Speciesvirginica** |   1.582    |    0.103     |   15.37   | 2.215e-32  |

If I knit this to html (via Rstudio button that uses Rmarkdown to generate the HTML if I'm not wrong), the last table is not displayed as a table but as plain text in the HTML output.
If I use the md generated by knitr and transform it into html with pandoc the output is a table but the last column name becomes "Pr(>".

The first table without the last column is displayed correctly.


Solution

  • You can escape the pipes with a backslash (\|).