shearichard
shearichard

Reputation: 8372

R / htmltable - unicode characters aren't rendered in R Studio viewer

I have a question about the htmltable package of R.

I haven't used it before and when I try to render some data into HTML the unicode characters aren't handled well - or at least when seen in the R Studio viewer.

The results look like this with what unicode apostrophe not being rendered into anything recognisable :

enter image description here

This is what I did to get that result.

> download.file("https://sites.google.com/site/econometriks/docs/brazil.RData", "brazil2.RData")
> load("brazil2.RData")
> tab<-cbind("Internet"=table(brazil$internet))
> htmlTable(tab, rowlabel="User Status")

Is there some way I can pre-process the data or tell htmltable to behave differently so that the characters are handled properly ?

Upvotes: 1

Views: 552

Answers (1)

nilsole
nilsole

Reputation: 1733

This worked on my machine. RStudio does not like the Latin-1 apostrophe.

library("htmlTable")
download.file("https://sites.google.com/site/econometriks/docs/brazil.RData", "brazil2.RData")
load("brazil2.RData")
brazil$internet <- as.character(brazil$internet)
Encoding(brazil$internet) <- "latin1"
print(unique(brazil$internet))
# [1] "no"         "yes"        "don’t know"
brazil[,"internet"] <- gsub("’","'",brazil[,"internet"])
tab<-cbind("Internet"=table(brazil$internet))
htmlTable(tab, rowlabel="User Status")`

Upvotes: 1

Related Questions