-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error detecting locale - incomplete final line #233
Comments
same issue seems related to non english language |
I had the same issue with read.xlsx. It was solved with xlsx::read.xlsx. Thank you! |
Exactly same issue with the french language when deploying to shinyapps |
I wonder why we use |
My memory is very hazy, but I believe the issue is that |
The issue would be solved, i guess, if we could handle the weard encoding returned by system("systeminfo /FO csv"). On three different windows laptops (from France), I got the same output :
|
That makes sense. One option you could try as a workaround: setting the |
Could you please give an example on how to set the I have tried all sorts of ways such as I found a hacky way by setting Thank you in advance. |
You might need to set it within a |
FWIW Doing this works if we can assumes that it will always return systemInfo <- function() {
raw <- system("systeminfo /FO csv", intern = TRUE, wait = TRUE)
Encoding(raw) <- rep_len("latin1", length(raw))
info <- read.csv(textConnection(raw))
return(info)
} With CMD in Windows, we can also force to output in UTF-8 by changing the default code page. For example systemInfo <- function() {
commands <- c(
"@ECHO OFF",
"CHCP 65001 > nul",
"systeminfo /FO csv"
)
bat <- tempfile(fileext = ".bat")
on.exit(unlink(bat), add = TRUE)
writeLines(commands, bat, useBytes = TRUE)
raw <- system(bat, intern = TRUE, wait = TRUE)
info <- read.csv(textConnection(raw))
return(info)
} Git patchdiff --git a/R/locale.R b/R/locale.R
index f2d8b6b..74c7d37 100644
--- a/R/locale.R
+++ b/R/locale.R
@@ -78,7 +78,16 @@ systemLocale <- function() {
}
systemInfo <- function() {
- raw <- system("systeminfo /FO csv", intern = TRUE, wait = TRUE)
+ commands <- c(
+ "@ECHO OFF",
+ "CHCP 65001 > nul",
+ "systeminfo /FO csv"
+ )
+ bat <- tempfile(fileext = ".bat")
+ on.exit(unlink(bat), add = TRUE)
+ writeLines(commands, bat, useBytes = TRUE)
+ raw <- system(bat, intern = TRUE, wait = TRUE)
info <- read.csv(textConnection(raw))
return(info)
} Hope it helps |
Possible alternative approach from @gaborcsardi: utils::readRegistry("Control Panel\\International\\User Profile", hive = "HCU")$Languages
#> [1] "en-US" "de-DE" "es-ES" "hu" We're just exploring how far back in time this key exists. |
Regarding alternative, when targeting windows only, powershell can be an option shell("(Get-WinSystemLocale).Name", "powershell", intern = TRUE)
#> [1] "fr-FR"
system2("powershell", c("-Command", "(Get-WinSystemLocale).Name"), stdout = TRUE)
#> [1] "fr-FR" Available since windows 8/server2012 I think. Powershell is not used that much with R but I think it available by default on windows since some time. I use that in ps1 script but probably reading from registry is better from R. Just sharing in case it can help |
It needs Windows 8.1 it seems. But this works on Windows 10 and back to Vista, everywhere:
|
Hi,
When deploying to a RStudio Connect server with
rsconnect
, I have this warning.I believe there is something wrong in the process of detecting local on Windows.
I found that
rsconnect:::systemInfo
is used for detecting local on windows. The commandsysteminfo /FO csv
is called withsystem
. I get back a result in a csv format. Currently, the functionsystemInfo
useread.csv
that cause the error. If I usereadr::read_csv
no more error.Not sure what is the encoding of the string return by
systeminfo /FO csv
.So I tested with what I know
If we try to provide encoding in some way
Do you have any idea on this ? What fix could be done ?
Created on 2018-01-10 by the reprex package (v0.1.1.9000).
The text was updated successfully, but these errors were encountered: