简体   繁体   中英

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 .

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

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 :

install.packages错误

Now, the translation of é into é is the result of decoding the UTF-8-encoded character é assuming a WINDOWS-1252 encoding. So my guess is that R assumes the wrong encoding for file names.

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 . 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.

Additional info: I got the output of 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.

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.

(Note that the R GUI works flawlessly.)

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. To do this, one has to create or modify an environment variable called HOME.

For example, setting a user environment variable HOME to "C:\\", RStudio will consider ~ to be C:. R's configuration file placed in C:\\ will be read at startup.

As far as I know, HOME is not a default environment variable on Windows and defining it should not interfere with "normal" Windows applications.

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:

install.packages() has a lib parameter, where you can specify where you'd like to have your packages installed.

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):

> 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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