[R] printing ISO/8859-1 characters

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Oct 25 19:21:23 CEST 2004

On Mon, 25 Oct 2004, Halldor Björnsson wrote:

> Hi,
> I ran into an odd problem with the print command for R-2.0 on a windows 
> machine.
> The icelandic character thorn (þ,Þ) which is included in in the Latin-1
> character set [iso/8859-1 char# 222 (upper case) and #254 (lower case)]
> prints out incorrectly. Instead of getting the correct
> character I get the octal codes for upper and lower case thorn (\336 or 
> \376). This only happens on a windows machine, but not on a linux box.
> This is not some problem generic to the Latin-1 characters. I get
> all accented characters correctly and also the character eth (?Ð).
> Its only thorn thats problematic...
> This problem also shows up on the commandline a <-"Þ" works
> ok, but print(a) or just:
> a
> returns the octal number.
> However, when using THORN in plotlabels it works fine.
> If anyone knows how to fix this I would be very happy to hear from them...

It's a bug in your version of Windows.  print() tests for printable 
characters, by  if(isprint((int)*p))  in src/utils/printutils.c, and
that in turn asks Windows about your locale.  (The Rgui console used to do 
this, but Windows crashed too often when it did.)

Assuming your machine is set correctly to an Icelandic locale, the only 
solution I know of is to write your own replacement for isprint and 
compile that into a build of R.  If you can, it might be worth trying 
another version of Windows: we saw something similar in Czech that worked 
in Windows XP but not 2000.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list