Skip to content

Instantly share code, notes, and snippets.

@kevinushey
Created September 23, 2016 18:24
Show Gist options
  • Save kevinushey/32ea69f6c64a4171d987405712c6a387 to your computer and use it in GitHub Desktop.
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.
# 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)
}
}
@maverpig
Copy link

maverpig commented Aug 4, 2017

I find the reason!
All the errors was just because the environment variables TMP and TEMP I set had non-ASCII characters in them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment