如何在RMarkdown Shiny中展示中国特色

时间:2018-01-26 01:54:31

标签: r encoding shiny r-markdown

我想使用RMarkdown和Shiny中文字符。任何想法为什么以下不会起作用?

-

--
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 个答案:

答案 0 :(得分:1)

您在Windows上使用RStudio吗?不幸的是,字符编码在Windows上是地狱......

我能在Windows上使用它的唯一方法是解决方法:

1, 似乎通过Sys.setlocale设置区域设置无法正常工作。而是使用.Rprofilefile.edit('.Rprofile')内设置区域设置。

.Rprofile的内容

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

2,使用RStudio中的编码保存Markdown文件(我选择了x_Chinese-EtenSave with encoding

3,完成这两个步骤后,输出仍为NA ...但如果您使用renderPrint代替print,则会神奇地起作用。

renderPrint