[R] Problem with writing a CSV file in UTF-8 formate

Matt Shotwell shotwelm at musc.edu
Tue Jun 22 19:01:35 CEST 2010


Duncan and I had nearly identical code examples in our replies. This is
becoming a theme. Great minds think alike??? :-)

UTF-8 is backward compatible with ASCII. Hence, if your "|" separated
table contains only ASCII, the UTF-8 encoded file may be
indistinguishable from an ASCII encoded file. Maybe notepad can't tell
it's unicode, and uses ANSI (codepage?) to represent its best guess.

Does your table contain non-ASCII characters?

-Matt

On Tue, 2010-06-22 at 10:42 -0400, Duncan Murdoch wrote:
> On 22/06/2010 10:39 AM, venkata kirankumar wrote:
> > Hi Murdoch,
> > first of all thanks allot for your suggestion.
> > I tried the way you suggested but while opening in notepad and checking its
> > showing  that the file is in ANSI
> > can any thing else I can do for this
> >   
> What makes you think notepad is able to detect the encoding properly?
> 
> Duncan Murdoch
> > Thanks in advance
> > kiran
> > On Tue, Jun 22, 2010 at 7:02 PM, Duncan Murdoch <murdoch.duncan at gmail.com>wrote:
> >
> > > On 22/06/2010 9:00 AM, venkata kirankumar wrote:
> > >
> > >> Hi all,
> > >> I have a problem with writing a *.CSV file in UTF-8 formate
> > >>
> > >> I tried to write a dataframe named  "dfPREINDX" to the new file named
> > >> "preindx.csv" in below formate
> > >>
> > >>
> > >> write.table(dfPREINDX,PreIndex,fileEncoding="UTF-8",sep="|",row.names=FALSE)
> > >>
> > >> but its throed an error  like
> > >>
> > >> Error in write.table(dfPREINDX, "preindx.csv", fileEncoding = "UTF-8", sep
> > >> =
> > >> "|",  :
> > >>  unused argument(s) (fileEncoding = "UTF-8")
> > >>
> > >> can any one please help me how to create a file in UTF-8  formate.
> > >>
> > >
> > > The write.table has no fileEncoding argument.  To write to a non-native
> > > encoding, you need to open a connection with that encoding, and write to
> > > that.  For example:
> > >
> > > con <- file("preindx.csv", open="w", encoding="UTF-8")
> > > write.table(dfPREINDX, con, sep="|",row.names=FALSE)
> > > close(con)
> > >
> > > Duncan Murdoch
> > >
> > >
> > >
> >
> >
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
-- 
Matthew S. Shotwell
Graduate Student
Division of Biostatistics and Epidemiology
Medical University of South Carolina
http://biostatmatt.com



More information about the R-help mailing list