多操作系统上的RMarkdown utf-8错误 [英] RMarkdown utf-8 error on mutliple operating systems
问题描述
在多个操作系统上使用RMarkdown时遇到问题.
We have a problem using RMarkdown on multiple operating systems.
最初,在Linux系统(Ubuntu 12.04 LTS)上创建一个.Rmd文件,然后将其推送到GitHub存储库.
Initially, an .Rmd file is created on a Linux system (Ubuntu 12.04 LTS) and then pushed to a GitHub repo.
在此系统上,可以对其进行编译(编织")而没有问题.
It can be compiled ("knitted") without problems on this system.
然后在安装了RStudio的Windows 7计算机上将其拉出.
It is then pulled on a Windows 7 machine with RStudio installed.
在尝试编译时,出现以下错误:
There, when trying to compile, the following error shows up:
Error in yaml::yaml.load(front_matter) :
Reader error: invalid leading UTF-8 octet: #FC at 66
Calls: <Anonymous> -> parse_yaml_front_matter -> <Anonymous> -> .Call
Execution halted
- 在Windows系统上创建另一个.Rmd文件时,它可以正常工作.
- 在Windows系统上创建另一个.Rmd文件,并将除有问题的"文件的前几行以外的所有内容复制到另一个.Rmd文件,并编译该文件时,它可以正常工作.
我在两个操作系统上都以十六进制(在Sublime中)比较了两个文件:它们完全相同.
I compared both files in HEX (in Sublime) on both operating systems: They are EXACTLY the same.
其他人以前见过该错误吗?
Has somebody else seen that error before?
In general, it seems that Unicode is not correctly recognized by either R, RStudio or knitr on Windows. When I type in some Umlauts in a new .Rmd file, and knit it, I get output such as "öää". In RStudio > Tools > Global options, I set the Default text encoding to "UTF-8". And I also did that for R, in the RProfile.site file (options(encoding="UTF-8")
).
更新2: library(rmarkdown); sessionInfo()
给出
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=German_Switzerland.1252 LC_CTYPE=German_Switzerland.1252 LC_MONETARY=German_Switzerland.1252
[4] LC_NUMERIC=C LC_TIME=German_Switzerland.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rmarkdown_0.4.2
loaded via a namespace (and not attached):
[1] digest_0.6.8 htmltools_0.2.6 tools_3.1.2
在Windows 7上,而在Ubuntu上是:
on Windows 7, whereas, on Ubuntu, it is:
R version 3.1.2 (2014-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rmarkdown_0.3.10
loaded via a namespace (and not attached):
[1] digest_0.6.8 htmltools_0.2.6 tools_3.1.2
我已经怀疑问题出在不同的地区...我该如何解决?
I already suspect the problem to be the diverging locale... how do I fix this?
推荐答案
对此我来晚了,但我通过将选项编码改回本机"解决了该问题:
I am extremely late to this, but I solved the issue by changing the options encoding back to "native":
options(encoding="native")
并将默认窗口编码更改为UTF-8(这打开了与其他程序的编码相关的其他问题的数量不可忽略的pandora框;因此,请谨慎对待).
And changing the default windows encoding to UTF-8 (which opened the pandora box of a non-negligible number of other issues related to the encoding of other programs; so, treat with caution).
这篇关于多操作系统上的RMarkdown utf-8错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!