Closed cderv closed 1 year ago
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 systeminfo
here instead of Sys.getlocale()
. It looks like this code is now quite old so any memory of why is probably long gone ...
My memory is very hazy, but I believe the issue is that Sys.getlocale()
is platform specific. In other words, on windows, you'll get a value that isn't meaningful to linux, which shinyapps.io runs under the hood. systeminfo
does provide a meaningful locale for linux.
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 :
system("systeminfo /FO csv", intern = TRUE, wait = TRUE)
[1] "\"Nom de l'h“te\",\"Nom du systŠme d'exploitation\",\"Version du systŠme\",\"Fabricant du systŠme d'exploitation\",\"Configuration du systŠme d'exploitation\ [TRUNCATED]"
That makes sense. One option you could try as a workaround: setting the rsconnect.locale
option, which should bypass the automatic detection code.
That makes sense. One option you could try as a workaround: setting the
rsconnect.locale
option, which should bypass the automatic detection code.
Could you please give an example on how to set the rsconnect.locale
to English?
I have tried all sorts of ways such as options(rsconnect.locale = "en_US")
and even changing my Windows locale to English (from Chinese) but the default locale detected by shinyapps.io is still CN.
I found a hacky way by setting Sys.setlocale("LC_ALL", "C")
before the app is called, but in such a way, all my date formatting from lubridate
broke.
Thank you in advance.
You might need to set it within a .rsconnect_profile
, especially if you're trying to deploy from RStudio. See ?rsconnect::options
for more details.
FWIW systeminfo /FO csv
will return in Latin1 encoding. This is default for CMD output.
Doing this works if we can assumes that it will always return latin1
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)
}
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:
utils::readRegistry(hive = "HCU", "Control Panel\\International")$LocaleName
#> en-US
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 knowIf 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).