[R-lang] Re: writing Unicode files from R

Nathaniel Smith njs@pobox.com
Wed Oct 20 07:43:03 PDT 2010


On Wed, Oct 20, 2010 at 6:25 AM, Scott Jackson <scottuba@gmail.com> wrote:
> Has anyone worked with getting Unicode *out* of R?  I've had some
> success getting Unicode that began life in an Excel doc, text file,
> etc. into R and getting R to display the Unicode characters (e.g.,
> Arabic, Cyrillic) in the GUI and in plots.  However, whenever I've
> wanted to manipulate some data that has some Unicode text and get it
> out of R into a file that could be then opened in Excel and read by
> humans, I've gotten stuck.  Using write.table() or write() or cat() or
> even writeClipboard() have all resulted in ASCII renderings of the
> Unicode (e.g., <U+0001>), which I can't manage to get back into their
> human-readable Unicode characters in Excel, Notepad, or other text
> editors.

I just tried using write() to dump some unicode to a file, and for me
it seemed to work fine without doing anything special -- so I can't
actually tell for sure whether this will work. But have you tried
adjusting your encoding options? I would try
  options(encoding="UCS-2LE")  # More common on Windows
or
  options(encoding="UTF-8")  # More common on Unix/OS X

-- Nathaniel



More information about the ling-r-lang-L mailing list