简体   繁体   English

Windows 8上的R / Rstudio:当用户名包含特殊/重音/非ASCII字符时,如何在用户主目录中安装软件包

[英]R/Rstudio on Windows 8: how to install packages in user home when username contains special/accented/non-ascii characters

Premise: I'm trying to debug a student's problem, I will make the question more precise as I get more details. 前提:我正在尝试调试学生的问题,当我获得更多详细信息时,我将使问题更精确。 It may be due to some earlier installation issue. 这可能是由于某些较早的安装问题所致。

When first installing packages via install.packages , R proposes to create a personal library in the user's home, C:\\Users\\username\\Documents . 首次通过install.packages安装软件包时,R建议在用户家中创建个人库C:\\Users\\username\\Documents

对话框:您想使用个人图书馆吗?

In this case the username contains an accented character, which looks already scrambled in the dialog: 在这种情况下,用户名包含一个带重音的字符,该字符在对话框中看起来已经被打乱了:

对话框:您想创建个人图书馆吗?

and the command fails because it tries to create a new folder C:\\Users\\Noémie instead of using the existing C:\\Users\\Noémie : 该命令失败,因为它尝试创建一个新文件夹C:\\Users\\Noémie而不是使用现有的C:\\Users\\Noémie

install.packages错误

Now, the translation of é into é is the result of decoding the UTF-8-encoded character é assuming a WINDOWS-1252 encoding. 现在,翻译éé是UTF-8编码的字符的解码结果é假设WINDOWS-1252的编码。 So my guess is that R assumes the wrong encoding for file names. 所以我的猜测是R假设文件名的编码错误。

I already spent some time looking for a solution, there's a lot of info on file content encoding issues, but I did not find any on filename encoding issues with R on Windows, aside from this unanswered question . 我已经花了一些时间寻找解决方案,关于文件内容编码问题有很多信息,但是除了这个未解决的问题之外,我在Windows上找不到关于R的文件名编码问题的任何信息。 And I guess there must be a lot of people having special characters in their Windows username, who still manage to run R. So this seems to be an uncommon error, and there should be a way around it. 而且我猜想很多人的Windows用户名中都有特殊字符,他们仍然设法运行R。因此,这似乎是一个罕见的错误,应该有一种解决方法。

Additional info: I got the output of sessionInfo() : 附加信息:我得到了sessionInfo()的输出:

R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=French_Belgium.1252  LC_CTYPE=French_Belgium.1252       LC_MONETARY=French_Belgium.1252
[4] LC_NUMERIC=C                    LC_TIME=French_Belgium.1252

A student of mine had the same problem. 我的一个学生有同样的问题。 Furthermore, when the path to the home directory (represented as ~ throughout RStudio) contains accented letters, RStudio does not read R's configuration files ~/.Renviron and ~/.Rprofile. 此外,当主目录的路径(在整个RStudio中用〜表示)包含重音字母时,RStudio不会读取R的配置文件〜/ .Renviron和〜/ .Rprofile。

This creates a sort of catch-22 for package installation: RStudio cannot create its default personal library and you cannot specify another one by setting R_LIBS_USER in ~/.Renviron. 这会为包安装创建一个catch 22:RStudio无法创建其默认个人库,并且您无法通过在〜/ .Renviron中设置R_LIBS_USER来指定另一个。

(Note that the R GUI works flawlessly.) (请注意,R GUI可以正常工作。)

From what I could gather, the following seems to be a viable workaround: fool RStudio into thinking the home directory is somewhere else along a path without accented letters. 据我所知,以下似乎是一个可行的解决方法:欺骗RStudio认为主目录位于路径中没有重音字母的其他位置。 To do this, one has to create or modify an environment variable called HOME. 为此,必须创建或修改一个称为HOME的环境变量。

For example, setting a user environment variable HOME to "C:\\", RStudio will consider ~ to be C:. 例如,将用户环境变量HOME设置为“ C:\\”,RStudio会将〜视为C:。 R's configuration file placed in C:\\ will be read at startup. R的配置文件放在C:\\中,将在启动时读取。

As far as I know, HOME is not a default environment variable on Windows and defining it should not interfere with "normal" Windows applications. 据我所知,HOME不是Windows上的默认环境变量,并且定义它不会干扰“正常” Windows应用程序。

I'm running Win10 32bit and an older version of R ( R version 3.1.0 (2014-04-10) -- "Spring Dance" Platform: i386-w64-mingw32/i386 (32-bit) ), but the following solution might work for you: 我正在运行Win10 32位和R的旧版本( R version 3.1.0 (2014-04-10) -- "Spring Dance" Platform: i386-w64-mingw32/i386 (32-bit) ),但是以下解决方案可能适合您:

install.packages() has a lib parameter, where you can specify where you'd like to have your packages installed. install.packages()具有一个lib参数,您可以在其中指定要将软件包安装到的位置。

I was able to successfully run the commands 我能够成功运行命令

install.packages('plyr', lib='C:/Noémie')

and

install.packages('plyr', lib='C:/Users/Roland')

I did not succeed in running the following, which is likely due to Windows permissions and being able to write in a User directory which is not yours (as I'm Roland, not Noémie): 我无法成功运行以下命令,这可能是由于Windows权限以及能够在非您的用户目录中写入的原因(因为我是Roland,而不是Noémie):

> install.packages('plyr', lib='C:/Users/Noémie')
Warning in install.packages :
'lib = "C:/Users/Noémie"' is not writable
Error in install.packages : unable to install packages

Does the last command solve your problem for you? 最后一条命令会为您解决问题吗? If not, playing around with the encoding of the character vector passed to lib might present a solition. 如果不是这样,尝试传递传递给lib的字符向量的编码可能会很孤立。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM