Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持中文问题 #142

Closed
WLswert opened this issue Jun 28, 2016 · 8 comments
Closed

支持中文问题 #142

WLswert opened this issue Jun 28, 2016 · 8 comments
Milestone

Comments

@WLswert
Copy link

WLswert commented Jun 28, 2016

你好,在window系统环境下,我这边出现以下两个问题。虽然有方法避免,但是还是希望更好的支持中文。
1、用bookdown时在.rmd文档中写中文不会乱码,但是在用wordcloud2包画动态词云图时,中文会乱码。并且不在用bookdown时,用默认的模版可以画出中文词云图。

2、在_bookdown.yml中写入中文,改成UTF-8编码,一直都提示报错:句法分析器1行里不能有多字节字符。且试过其他编码,均无法成功,用yaml::yaml.load()命令测试中文字符串,可以通过,但是会乱码,需要进行转换。

以下是 sessionInfo() 的信息,没有升级3.3.1,因为另外一台电脑是最新版的R与RStudio,上述问题同样存在。
`R version 3.3.0 (2016-05-03)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936
[2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] magrittr_1.5 R6_2.1.2 rsconnect_0.4.3 htmltools_0.3.5 pbdZMQ_0.2-3
[6] tools_3.3.0 yaml_2.1.13 Rcpp_0.12.5 stringi_1.1.1 rmarkdown_0.9.6.14
[11] stringr_1.0.0 digest_0.6.9 evaluate_0.9 `

@yihui
Copy link
Member

yihui commented Jun 28, 2016

真是怪哉,_bookdown.yml 含有中文时我在 Windows 下可以加载啊。我再试试。wordcloud2 的问题也等我打开 Windows 试试。

@yihui
Copy link
Member

yihui commented Jun 29, 2016

试试这里最新版的 bookdown 以及我的 r-ninja 库吧。

@WLswert
Copy link
Author

WLswert commented Jun 30, 2016

谢谢大牛!
_bookdown.yml中的中文问题刚试了一下,确实可以了。不过yaml的这个问题是个大坑呀。

为虾米动态词云图还是乱码呢?看了一下,用htmlwidget框架传过去的数据都是乱码,将这些字符,在R里转换了一下,用UTF-8转化为GBK就成汉字了。而不用bookdown,用Rmd时画词云不会乱码。。。。

@yihui
Copy link
Member

yihui commented Jun 30, 2016

5月初我在查这个案子的时候发现了类似的问题 rstudio/rmarkdown#686 刚看了一下,当时我找到的一个解决方案可以解决你的问题,但他们那边的问题还是没能完全解决。待我再研究一下。

yihui added a commit to rstudio/htmltools that referenced this issue Jul 9, 2016
This fixes rstudio/rmarkdown#686 and rstudio/bookdown#142. The problem in these cases is that `chunks` is encoded in UTF-8 and contains multibyte characters, but `strval`'s encoding is unknown (native). After gsub(useBytes = TRUE), `strval`'s encoding is still unknown, and on Windows, unknown/native != UTF-8, so when the restored HTML is written out, the multibyte characters are garbled.
@yihui
Copy link
Member

yihui commented Jul 9, 2016

@WLswert 我找到问题了,在 htmltools 里,请帮忙测试:

devtools::install_github('rstudio/htmltools@bugfix/utf8-preserved-chunks')

@WLswert
Copy link
Author

WLswert commented Jul 11, 2016

@yihui 我这边测试了,问题解决了!
谢谢大神!!!

@yihui
Copy link
Member

yihui commented Jul 11, 2016

忒好了!

@yihui yihui modified the milestone: v0.1 Jul 12, 2016
@github-actions
Copy link

github-actions bot commented Nov 6, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants