@@ -922,15 +922,24 @@ setServerInfo <- function(...) {
922
922
# see if the file can be read as UTF-8 on Windows, and converted from UTF-8 to
923
923
# native encoding; if the conversion fails, it will produce NA's in the results
924
924
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)
925
931
if (! isWindows()) return (' UTF-8' )
926
932
927
933
x <- readLines(file , encoding = ' UTF-8' , warn = FALSE )
928
934
isUTF8 <- ! any(is.na(iconv(x , ' UTF-8' )))
929
935
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
931
939
if (identical(charToRaw(readChar(file , 3L , TRUE )), charToRaw(' \U FEFF' ))) {
932
940
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.' )
934
943
if (getRversion() < ' 3.0.0' )
935
944
stop(' R does not support UTF-8-BOM before 3.0.0. Please upgrade R.' )
936
945
return (' UTF-8-BOM' )
@@ -939,7 +948,8 @@ checkEncoding <- function(file) {
939
948
enc <- getOption(' encoding' )
940
949
msg <- c(sprintf(' The file "%s" is not encoded in UTF-8. ' , file ),
941
950
' 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.' )
943
953
if (enc == ' UTF-8' ) stop(msg )
944
954
# if you publish the app to ShinyApps.io, you will be in trouble
945
955
warning(c(msg , ' Falling back to the encoding "' , enc , ' ".' ))
0 commit comments