我想使用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)
```
答案 0 :(得分:1)
您在Windows上使用RStudio吗?不幸的是,字符编码在Windows上是地狱......
我能在Windows上使用它的唯一方法是解决方法:
1,
似乎通过Sys.setlocale
设置区域设置无法正常工作。而是使用.Rprofile
在file.edit('.Rprofile')
内设置区域设置。
.Rprofile的内容
Sys.setlocale(category = "LC_ALL", locale = "chs")
2,使用RStudio中的编码保存Markdown文件(我选择了x_Chinese-Eten
)
3,完成这两个步骤后,输出仍为NA
...但如果您使用renderPrint
代替print
,则会神奇地起作用。