I am using the sj
packages within R Markdown. However, I am encountering encoding problems.
My problem: If you run the following lines, you'll get one cross table with encoding problems and a second cross table, which solves this issue.
library(sjPlot)
library(sjmisc)
library(sjlabelled)
Var1 <- factor(sample(1:6, 200, replace = T))
Var1 <- factor(Var1,
levels = c("1","2","3","4","5", "6"),
labels = c("Zu Hause",
"Am Im Büro",
"In der Schule bzw. an der Universität",
"An einem öffentlichen Ort",
"Unterwegs",
"Außer Haus"))
sjt.xtab(Var1, Var1)
sjt.xtab(Var1, Var1, encoding = "UTF-8")
Pic2: with encoding=UTF8
[][
However, if you try to run this in a Rmd-file, the solution with encoding = "UTF-8"
doesn't work anymore.
```{r echo = FALSE}
library(sjPlot)
library(sjmisc)
library(sjlabelled)
Var1 <- factor(sample(1:6, 200, replace = T))
Var1 <- factor(Var1,
levels = c("1","2","3","4","5", "6"),
labels = c("Zu Hause",
"Am Im Büro",
"In der Schule bzw. an der Universität",
"An einem öffentlichen Ort",
"Unterwegs",
"Außer Haus"))
sjt.xtab(Var1, Var1)
sjt.xtab(Var1, Var1, encoding = "UTF-8")
```
The output looks like Pic1, but should look like Pic2
Or
`r sjt.xtab(Var1, Var1,
title = "<br/><h1> Ort /h1> <br/>Beschreibung: Bla Bla.",
wrap.labels = 5555,
encoding = "UTF-8",
no.output=TRUE)$knitr`
The output looks like Pic1, but should look like Pic2
A rmarkdown::render("File_in.Rmd", output_file = "File_out.html", encoding = "UTF-8")
doesn't help as well.
I think, the problem always occur, when the labels of the second variable (gives the rows) in sjt.xtab()
got umlauts (ä,ü,ö,ß).
It would be great to hear your solutions!
Julian