R,Rstudio控制台编码窗口 [英] R, Rstudio Console Encoding Windows

查看:509
本文介绍了R,Rstudio控制台编码窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有办法在Windows上的Rstudio中更改控制台编码吗?

I there a way to change the console encoding in Rstudio on windows?

这与读取特定编码的文件或源脚本无关,而是与更改控制台编码(Sys.getlocale编码产生)有关.

This is not about reading files or sourcing scripts in a specific encoding but about changing the console encoding (the encoding Sys.getlocale yields).

这通常不是什么大问题,但是我尝试创建一个包,并且在某些字符串和符号中使用德国变音符号. roxygen2UTF-8编码一起使用效果最佳,但如果源文件不在控制台/系统编码中,则covr会给出错误消息.

This is usually not a big problem, but i try to create a package and I'm using german umlauts in some strings and symbols. roxygen2 works best with UTF-8 encoding but covr gives an error if the source files are not in the console/system encoding.

(如果有解决roxygen2covr问题的方法,这也会有所帮助.其他信息:我从控制台调用covr::package_coverage,然后通过Rstudios Build命令调用roxygen2.)

(If there's a workaround for the roxygen2 and covr problem this would also help. Addintional info: I call covr::package_coverage from the console and I call roxygen2 via Rstudios Build command.)

和sessioninfo:

and sessioninfo:

sessionInfo()
# R version 3.4.2 (2017-09-28)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows >= 8 x64 (build 9200)
# 
# Matrix products: default
# 
# locale:
# [1] LC_COLLATE=German_Austria.1252  LC_CTYPE=German_Austria.1252    LC_MONETARY=German_Austria.1252 LC_NUMERIC=C                    LC_TIME=German_Austria.1252    

更新:在Rstudio中搜索通过文件提供错误的函数,并加载devtools::load_all(".")并且RStudio gui给出错误/错误的编码.

Update: Sourcing the function that gives an error through the file in Rstudio works, loading with devtools::load_all(".") and the RStudio gui gives the error/wrong encoding.

推荐答案

如果您要问如何在Windows上将语言环境更改为支持UTF-8的语言环境,答案是您不能.

If you're asking how to change the locale to a UTF-8-capable one on Windows, the answer is you can't.

当您调用Sys.setlocale时,R将调用setlocale系统功能.不幸的是,没有一种方法可以为字符类型(LC_CTYPE)指定UTF-8.参见 https://stackoverflow.com/a/4336010/6233565 .

When you call Sys.setlocale, R will call the setlocale system function. Unfortunately, there isn't a way to specify UTF-8 for the character type (LC_CTYPE); see https://stackoverflow.com/a/4336010/6233565 .

您可以 做的是将语言环境更改为 https://msdn.microsoft.com/library/windows/desktop/dd373814.aspx .例如,要更改为Windows-1251,请执行

What you can do is change the locale to one of those described at https://msdn.microsoft.com/library/windows/desktop/dd373814.aspx . For example, to change to Windows-1251, do

Sys.setlocale("LC_CTYPE", ".1251")

希望在将来的某个时候,您将能够在Windows上编写UTF-8编码的数据.目前,这是不可能的.所有输出都通过本机语言环境: https://stat. ethz.ch/pipermail/r-devel/2017-June/074556.html

Hopefully, at some point in the future you will be able to write UTF-8 encoded data on Windows. Currently, that's not possible. All output goes through the native locale: https://stat.ethz.ch/pipermail/r-devel/2017-June/074556.html

这篇关于R,Rstudio控制台编码窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆