Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to knit2html with UTF-8 encoding?

My .Rmd file contains multilingual text. When I load the html page produced by knit2html to my joomla site the multilingual text has been replaced by squares. Do you know of a way to request a utf-8 encoded html page, or any other way to overcome the problem?

like image 693
George Dontas Avatar asked Jul 02 '12 16:07

George Dontas


People also ask

Is UTF-8 the same as UTF-8?

UTF-8 is a valid IANA character set name, whereas utf8 is not. It's not even a valid alias. it refers to an implementation-provided locale, where settings of language, territory, and codeset are implementation-defined.

Can an ASCII file be read as UTF-8?

The first 128 characters in the Unicode library match those in the ASCII library, and UTF-8 translates these 128 Unicode characters into the same binary strings as ASCII. As a result, UTF-8 can take a text file formatted by ASCII and convert it to human-readable text without issue.


1 Answers

Update:

RStudio (>= 0.97.x) and knitr (>= 1.2) know how to handle the file encoding now. RStudio will pass the file encoding to the encoding argument of knit() (e.g. knit('foo.Rmd', encoding = 'UTF-8')). In short, upgrading RStudio and knitr will solve the problem.

Please ignore the answer below; it is no longer an appropriate solution.


I did it like this (using RStudio):

  1. For the .Rmd I chose "Save with encoding" then I selected UTF-8
  2. Before calling knit2html() I gave: options(encoding = 'UTF-8')

That did the trick

like image 70
George Dontas Avatar answered Sep 23 '22 07:09

George Dontas