Skip to content

Commit ffead9e

Browse files
committed
add explanations of skipping *nix when checking encoding, and point to the shiny dev center article
1 parent 983e7e9 commit ffead9e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

R/utils.R

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,15 +922,24 @@ setServerInfo <- function(...) {
922922
# see if the file can be read as UTF-8 on Windows, and converted from UTF-8 to
923923
# native encoding; if the conversion fails, it will produce NA's in the results
924924
checkEncoding <- function(file) {
925+
# skip *nix because its locale is normally UTF-8 based (e.g. en_US.UTF-8), and
926+
# *nix users have to make a conscious effort to save a file with an encoding
927+
# that is not UTF-8; if they choose to do so, we cannot do much about it
928+
# except sitting back and seeing them punished after they choose to escape a
929+
# world of consistency (falling back to getOption('encoding') will not help
930+
# because native.enc is also normally UTF-8 based on *nix)
925931
if (!isWindows()) return('UTF-8')
926932

927933
x <- readLines(file, encoding = 'UTF-8', warn = FALSE)
928934
isUTF8 <- !any(is.na(iconv(x, 'UTF-8')))
929935
if (isUTF8) return('UTF-8')
930-
# check if there is a BOM character
936+
# check if there is a BOM character: this is also skipped on *nix, because R
937+
# on *nix simply ignores this meaningless character if present, but it hurts
938+
# on Windows
931939
if (identical(charToRaw(readChar(file, 3L, TRUE)), charToRaw('\UFEFF'))) {
932940
warning('You should not include the Byte Order Mark (BOM) in ', file, '. ',
933-
'Please re-save it in UTF-8 without BOM.')
941+
'Please re-save it in UTF-8 without BOM. See ',
942+
'http://shiny.rstudio.com/articles/unicode.html for more info.')
934943
if (getRversion() < '3.0.0')
935944
stop('R does not support UTF-8-BOM before 3.0.0. Please upgrade R.')
936945
return('UTF-8-BOM')
@@ -939,7 +948,8 @@ checkEncoding <- function(file) {
939948
enc <- getOption('encoding')
940949
msg <- c(sprintf('The file "%s" is not encoded in UTF-8. ', file),
941950
'Please convert its encoding to UTF-8 ',
942-
'(e.g. use the menu `File -> Save with Encoding` in RStudio).')
951+
'(e.g. use the menu `File -> Save with Encoding` in RStudio). ',
952+
'See http://shiny.rstudio.com/articles/unicode.html for more info.')
943953
if (enc == 'UTF-8') stop(msg)
944954
# if you publish the app to ShinyApps.io, you will be in trouble
945955
warning(c(msg, ' Falling back to the encoding "', enc, '".'))

0 commit comments

Comments
 (0)