0

I'm writing a html report with rmarkdown. Inside it, there is an interactive data table, made with R's "DT" package.

library(DT)
library(xlsx)
tablename = read.xlsx("thetable.xlsx",sheetIndex=1,encoding="UTF-8")
datatable(tablename, options = list(pageLength = 5))

But inside the data table, some UTF-8 characters get messed up. I can't figure out why. Whenever I check the strings in R they're correct and everthing in the text is fine too.

The same characters that gets messed up also appear normally in some other lines of the table. Is there a way to force the characters to appear excatly how they appear in R?

VFreguglia
  • 2,129
  • 4
  • 14
  • 35
  • 1
    You need to edit with a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) if you want to get an answer. – alistaire Apr 13 '16 at 02:22
  • I just found out the problem is in the characters read from the xlsx file. The 34th character of the first string is an "í". When I run the code, it displays as an "Â" in the html, but if I use `substr(table[1,1], 34, 34)="í"` to insert the character manually it works. So the problem must happen when reading from the xlsx file. – VFreguglia Apr 13 '16 at 02:50
  • What characters are you dealing with here exactly? Chinese or other language? I faced that issue in the past and resolved (reading Chinese characters) by reading data with the XLConnect package. – JohnCoene Apr 13 '16 at 03:20

0 Answers0