Tony Breyal
2011-Feb-21 13:08 UTC
[R] How to source() a .R file which was saved using UTF-8 encoding on Windows?
Dear all, [Note: This was originally posted over at Stack Overflow, but it was suggested that the problem may be an error in R on Windows, so I have cross posted over here too. ref: http://goo.gl/pd54D) The following, when copied and pasted directly into R works fine:> character_test <- function() print("R??????GNU S????????????????????????????????????...") > character_test()[1] "R??????GNU S??????????????,???????,?????????????..." However, if I make a file called character_test.R containing the EXACT SAME code, save it in UTF-8 encoding (so as to retain the special Chinese characters), then when I source() it in R, I get the following error:> source(file="C:\\Users\\Tony\\Desktop\\character_test.R", encoding = "UTF-8")Error in source(file = "C:\\Users\\Tony\\Desktop\\character_test.R", encoding = "utf-8") : C:\Users\Tony\Desktop\character_test.R:3:0: unexpected end of input 1: character.test <- function() print("R 2: ^ In addition: Warning message: In source(file = "C:\\Users\\Tony\\Desktop\\character_test.R", encoding = "UTF-8") : invalid input found on input connection 'C:\Users\Tony\Desktop \character_test.R' Any help you can offer in solving and helping me to understand what is going on here would be much appreciated. Best, Tony Breyal ### Session information ###> sessionInfo() # Windows 7 Pro x64R version 2.12.1 (2010-12-16) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 [2] LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods [7] base loaded via a namespace (and not attached): [1] tools_2.12.1 and> l10n_info()$MBCS [1] FALSE $`UTF-8` [1] FALSE $`Latin-1` [1] TRUE $codepage [1] 1252
Possibly Parallel Threads
- Running R at a specific time - alternative to Sys.sleep() ?
- How to suppress errors from htmlTreeParse() function in XML package?
- readPDF() -- unsure how to install xpdf to make this work?
- Problem downloading webpages using batchfiles and RCurl from command line in Vista Basic - couldn't connect to host
- Extracting text from html code using the RCurl package.