I want to open R with input encoding UTF-8 fo开发者_JAVA百科r plots, and I can't seem to get it to work.
This is my (short) program in plot.R
plot(1:5, xlab="ř")
And this is what I get (I, sadly, have to use old version of R)
~/$ R <plot.R --no-save --encoding="utf-8"
R version 2.8.0 (2008-10-20)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> plot(1:5, xlab="ř")
Warning messages:
1: In title(...) :
conversion failure on 'ř' in 'mbcsToSbcs': dot substituted for <c5>
2: In title(...) :
conversion failure on 'ř' in 'mbcsToSbcs': dot substituted for <99>
3: In title(...) :
conversion failure on 'ř' in 'mbcsToSbcs': dot substituted for <c5>
4: In title(...) :
conversion failure on 'ř' in 'mbcsToSbcs': dot substituted for <99>
>
Googling anything R-related is a daunting task, so I am asking here. Am I doing something wrong? Or is it just the old R version?
edit: it seems like the error is not in input encoding, but in something else - when I write the letter as \u0159
, it does the same thing. So it is probably something with PDF fonts, I guess.
To reply to Joran: I don't really know the intricacies of R output devices; my R outputs by default into PDF. I have to use Fedora, release 8. (again, ancient, as well as the R version)
In R you generally need to spell things with proper upper and lowercase to each character, so you should try: "UTF-8"
Furthermore, I think UTF-8 is the default encoding for most European and North American systems, so why are you changing the default? I get no warnings with that code and character which looks like a lowercase r with a cupped "hat" on my system.
And R 2.8 is really ancient.
Searching: Use CRAN or r-project or language:r to limit your searching a bit, or go to RSiteSearch or RSeek. (I use different defaults for Baron's search site.)
I forced my admin to upgrade R and it works, but I needed to set up Sys.setlocale
first.
That about answers my question.
精彩评论