Skip to content

Instantly share code, notes, and snippets.

@kevinushey
Created September 23, 2016 18:24
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • 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 3, 2017

Hello!
I'm from china, just start to learn R.
I don't quite understand what this comment mean "# Place this in a file at '~/.Rprofile' to ensure it's sourced on startup".
I copy the code under the work directory, and name it with .Rprofile, but it doesn't work for me, maybe I try the wrong way.

When I try to run code below:
i <- c(10, 13, 45, 26, 23, 12, 24, 78, 23, 43, 31, 56)
j <- c(20, 65, 32, 32, 27, 87, 60, 13, 42, 51, 77, 35)
k <- data.frame('重量' = i, '运费' = j)
plot(k)

I find this error:
"Error in gzfile(file, "wb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "wb") :
cannot open compressed file 'C:/Users/??????/AppData/Local/Temp/RtmpAfbRLc/rs-graphics-2bd95ba4-75e3-4da5-adc4-74ec45d0ea69/d97896e9-fe62-4003-be34-2ac79cdf775a.snapshot', probable reason 'Invalid argument'
Graphics error: Plot rendering error"

In fact, this is the first time I leave a message on an English website, just hope i didn't bother you. Thanks!

@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