Rows that have more-than-three multybyte characters in total (like 3rd and 4th row below) seem printed inncorrectly.
library(knitr)
a <- read.csv(text = '
"A", "B", "C", "D", "E"
"a", "a", "a", 1.23, 1.23
"囧", "a", "a", 1.23, 1.23
"囧","囧","囧", 1.23, 1.23
"囧囧囧","a","a", 1.23, 1.23', stringsAsFactors = FALSE)
kable(a, format="pandoc")
A | B | C | D | E |
---|---|---|---|---|
a | a | a | 1.23 | 1.23 |
囧 | a | a | 1.23 | 1.23 |
囧 | 囧 | 囧 | 1.2 | 3 1.23 |
囧囧囧 | a | a | 1.2 | 3 1.23 |
By adding results='hold'
, the text before converted by pandoc is printed. As you see, table collapses when a row contains more-than-three “East Asian wide characters” because each column is only two spaces away.
kable(a)
##
##
## A B C D E
## ---- ---- --- ----- -----
## a a a 1.23 1.23
## 囧 a a 1.23 1.23
## 囧 囧 囧 1.23 1.23
## 囧囧囧 a a 1.23 1.23
To avoid this problem, we can specify "markdown"
, which uses |
as separator. Thanks @kohske!
kable(a, format = "markdown")
##
##
## |A |B |C | D| E|
## |:---|:---|:--|----:|----:|
## |a | a | a | 1.23| 1.23|
## |囧 | a | a | 1.23| 1.23|
## |囧 |囧 |囧 | 1.23| 1.23|
## |囧囧囧 |a |a | 1.23| 1.23|
kable(a, format = "markdown")
A | B | C | D | E |
---|---|---|---|---|
a | a | a | 1.23 | 1.23 |
囧 | a | a | 1.23 | 1.23 |
囧 | 囧 | 囧 | 1.23 | 1.23 |
囧囧囧 | a | a | 1.23 | 1.23 |