Is it possible to define encoding in R script?
Something like that (just example):
encoding("utf-8")
I know for Reopen with encoding in RStudio, but I am not looking for this.
Character strings in R can be declared to be encoded in "latin1" or "UTF-8" or as "bytes" . These declarations can be read by Encoding , which will return a character vector of values "latin1" , "UTF-8" "bytes" or "unknown" , or set, when value is recycled as needed and other values are silently treated as "unknown" .
You can view or change this default in the Tools : Options (for Windows & Linux) or Preferences (for Mac) dialog, in the General section. If you don't set a default encoding, files will be opened using UTF-8 (on Mac desktop, Linux desktop, and server) or the system's default encoding (on Windows).
## x is intended to be in latin1
x <- "fa\xE7ile"
Encoding(x)
Encoding(x) <- "latin1"
x
xx <- iconv(x, "latin1", "UTF-8")
Encoding(c(x, xx))
c(x, xx)
Encoding(xx) <- "bytes"
xx # will be encoded in hex
cat("xx = ", xx, "\n", sep = "")
http://www.inside-r.org/r-doc/base/Encoding
https://stat.ethz.ch/R-manual/R-devel/library/base/html/Encoding.html
how to read data in utf-8 format in R?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With