[R] Encoding issue with replacement operation

ronggui ronggui.huang at gmail.com
Mon May 4 06:50:58 CEST 2009

I have a length-1 character vector x, and I want to replace ' in the
character into ''. What I do now is to iconv x into suitable current
Encoding, then use gsub. It works well if I knows what x is (e.g.
Chinese charater), as I can use suitable locales to handle it.

### it works
x<- "some chinese character with ' in it"
Encoding(x) <- "UTF-8"

It would be great if I can achieve the same effect without the
suitable locales setting (e.g. even the Sys.setlocale(,"English")
instead of Sys.setlocale(,"CHS")). Is it possible? Thanks.

HUANG Ronggui, Wincent
PhD Candidate
Dept of Public and Social Administration
City University of Hong Kong
Home page: http://asrr.r-forge.r-project.org/rghuang.html

More information about the R-help mailing list