Rapporter / pander

An R Pandoc Writer: Convert arbitrary R objects into markdown
http://rapporter.github.io/pander/
Open Software License 3.0
294 stars 66 forks source link

Encoding discrepancy in multiline tables (line feed vs no line feed) #335

Closed dcomtois closed 5 years ago

dcomtois commented 5 years ago

Encodings, encodings. What would we do without those headaches I wonder. This concerns only Windows AFAIK.

I found that in multiline tables (using styles "grid" or "multiline"), strings are not encoded consistently; if there is a line feed (\n), things are fine. But when there is none, things go wrong:

x1 <- structure(list(
  Variable = c("SomeVar", "JustNAs"),
  Stats = c("Moy (é-t) : 1.02 (0.07)  \n \ Min : 0.86", "Aucune donnée valide")), 
  row.names = 1:2, 
  class = 'data.frame') 
pander::pander(x1)

## ----------------------------------------
##  Variable              Stats            
## ---------- -----------------------------
##  SomeVar    Moy (é-t) : 1.02 (0.07)     
##                     Min : 0.86          
## 
##  JustNAs       Aucune donnée valide    
## ----------------------------------------

The string in the upper right cell is encoded in latin1, in accordance with my locale setting, but the one on the bottom right is is actually encoded in UTF-8 (but interpreted as latin1).

Now by simply adding a \n at the end of the bottom string, we get consistent results:

x2 <- structure(list(
  Variable = c("SomeVar", "JustNAs"),
  Stats = c("Moy (é-t) : 1.02 (0.07)  \n \ Min : 0.86", "Aucune donnée valide\n")), 
  row.names = 1:2, 
  class = 'data.frame') 
pander::pander(x2)

## ----------------------------------------
##  Variable              Stats            
## ---------- -----------------------------
##  SomeVar    Moy (é-t) : 1.02 (0.07)     
##                     Min : 0.86          
## 
##  JustNAs       Aucune donnée valide     
## ----------------------------------------

Both strings are properly encoded in latin1. Unfortunately, since I can't build pander (neither on Windows nor on Linux), I can't debug it. :\

dcomtois commented 5 years ago

I realized that the fix for issue #296 (pander@06c2f65) solves this problem as well.