1

I would like to use RMarkdown and Shiny with Chinese characters. Any ideas why the below won't work?

-

--
title: "Untitled"
author: "test"
date: "26 January 2018"
output: html_document
runtime: shiny
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
Sys.setlocale(category = "LC_ALL", locale = "chs")
a<- "你"

```

```{r}
print(a)
```

Output

1 Answer 1

2

Are you using RStudio on Windows? Unfortunately character encoding is hell on Windows...

The only way I could get this to work on Windows is a workaround:

1, It seems that setting locale via Sys.setlocale doesn't work properly. Instead set the locale inside .Rprofile with file.edit('.Rprofile').

Content of .Rprofile

Sys.setlocale(category = "LC_ALL", locale = "chs")

2, Save your Markdown file with encoding in RStudio (I chose x_Chinese-Eten) Save with encoding

3, After completing these two steps, the output is still NA... but if you use renderPrint instead of print it magically works.

renderPrint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.