5

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.

2 Answers 2

2
## 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?

Sign up to request clarification or add additional context in comments.

Comments

2

A workaround is to write another script that has the following code:

source('C:/Script.R', encoding = 'UTF-8')

replace "C:/Script.R" with your script path & name.

Then when you call this script, it will run 'Script.R' with UTF-8 encoding.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.