Created
September 23, 2016 18:24
-
-
Save kevinushey/32ea69f6c64a4171d987405712c6a387 to your computer and use it in GitHub Desktop.
Some workarounds for mis-encoded environment variables on Windows for users with non-ASCII characters in their username.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Place this in a file at '~/.Rprofile' to ensure it's sourced on startup | |
.First <- function() { | |
# RStudio-specific startup | |
if (!is.na(Sys.getenv("RSTUDIO", unset = NA)) && | |
Sys.info()[["sysname"]] == "Windows") | |
{ | |
# work around mis-encoded environment variables | |
USERPROFILE <- Sys.getenv("USERPROFILE") | |
HOME <- file.path(USERPROFILE, "Documents", fsep = "\\") | |
R_USER <- HOME | |
R_LIBS_USER <- file.path(HOME, "R", "win-library", getRversion()[1, 1:2], fsep = "\\") | |
Sys.setenv( | |
HOME = HOME, | |
R_USER = R_USER, | |
R_LIBS_USER = R_LIBS_USER | |
) | |
# update library paths | |
if (!isTRUE(file.info(R_LIBS_USER)$isdir)) | |
dir.create(R_LIBS_USER, recursive = TRUE) | |
.libPaths(R_LIBS_USER) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I find the reason!
All the errors was just because the environment variables TMP and TEMP I set had non-ASCII characters in them.