lundi 30 mars 2015

R, utf-8 characters seem to fail in slidify

Edit: Still not solved, but I may be closer to the the cause of the situation. It turns out that while the Rmd itself was saved as UTF-8, many of the datasets used still reverted to ANSI on storage. Possibly an issue of mixed file types then. Best case slidify(file.Rmd, encoding="UTF-8") seems to compile the .md with characters correctly encoded, however during data processing errors due to encoding mismatches have happened already. These issues have not occurred on regular knitr Rmd to html conversions.


I'm working on converting an html Rmarkdown document into ioslides type Rmarkdown document, and I've stumbled onto an unexpected issue. The document works with no issues on regular knitr construction, but seems to run into character encoding issues with exactly the same code, environment and directory in slidify.


Namely, that knitr seems to crash when encountering a variable that contains a non-latin character (such as ä,ü,ö) and when it output text contains these characters they are replaced with "?" rectangles.


I am using the setup based on Claas-Thido Pfaff's example: http://ift.tt/19pAH31. I haven't yet found a place where it would specify or alter the locale (as exactly the same document works fine with html output.



---
title : Reproducible Reports
subtitle : With R, Knitr, LaTeX and Markdown
author : Claas-Thido Pfaff
job : http://ift.tt/1HX5ser
framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
widgets : [mathjax, bootstrap] # {mathjax, quiz, bootstrap}
mode : selfcontained # {standalone, draft}
knit : slidify::knit2slides
github :
author : changed
repo : reproducibility
---

```{r echo = FALSE, include = F, eval = T}
require(knitr)
hook_source_def = knit_hooks$get('source')
knit_hooks$set(source = function(x, options){
if (!is.null(options$verbatim) && options$verbatim){
opts = gsub(",\\s*verbatim\\s*=\\s*TRUE\\s*", "", options$params.src)
bef = sprintf('\n\n ```{r %s}\n', opts, "\n")
stringr::str_c(bef, paste(knitr:::indent_block(x, " "), collapse = '\n'), "\n ```\n")
} else {
hook_source_def(x, options)
}
})

require(ggplot2)
```


Any ideas? Thanks!


Update: The issue seems to occur when opening a file that contains utf-8 characters. Writing r "õ,ä,ü" within code brackets in text seems to work fine, but when opening a file with variables containing utf-8 characters causes problems in the script. These problems don't occur when using knitr to compile to html5. Anyone know what the differences between the two could be?



key <- read.csv("key1.csv", header = TRUE, sep = ";",
quote = "\"", dec = ".", fill = TRUE, comment.char = "")
print(key)


Adding and encoding parameter, or fileEncoding did not seem to help, html knitr doesn't seem to need it.


Update 2: There have been issues with encoding with slidify before, some of which have been solved, more info in these links: http://ift.tt/1CFtRSy, http://ift.tt/1ILcFfp, http://ift.tt/1CFtRSA, http://ift.tt/1ILcFfr


Aucun commentaire:

Enregistrer un commentaire