From murdoch.duncan at gmail.com  Mon Sep  5 12:31:51 2016
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Mon, 5 Sep 2016 06:31:51 -0400
Subject: [Rd] How to print UTF-8 encoded strings from a C routine to R's
 output?
In-Reply-To: <CAM0+Z0x8mJGuZxjqW9hbmQ6-oVaHUDRKid=rkFjwegOiRhPYgg@mail.gmail.com>
References: <CAM0+Z0x8mJGuZxjqW9hbmQ6-oVaHUDRKid=rkFjwegOiRhPYgg@mail.gmail.com>
Message-ID: <9270bb05-6418-633a-03ef-1a1fe68cf75b@gmail.com>

On 05/09/2016 12:40 AM, Lixin Gong wrote:
> Dear R experts,
>
> It seems that Rprintf has to be used to print from a C routine to guarantee
> to write to R?s output according to
> https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Printing.
>
> However if a string is UTF-8 encoded, non-ASCII characters (e.g., the
> infinity symbol http://www.fileformat.info/info/unicode/char/221e/index.htm)
> are misprinted.
> Is this an unsupported feature or is there a workaround for this limitation?

If you are working in a UTF-8 locale (as on most Unix-like systems), you 
should be fine.  If not (as is normal on Windows), you'll need to 
translate the string to the local encoding.  The Writing R Extensions 
manual section 6.11 tells you how to do the re-encoding.

Duncan Murdoch



[Rd] How to print UTF-8 encoded strings from a C routine to R's output?
Duncan Murdoch