[R] reading a text file with a stray carriage return

Walter R. Paczkowski dataanalytics at earthlink.net
Thu Mar 8 03:04:08 CET 2007


   Hi,
   I'm  hoping someone has a suggestion for handling a simple problem.  A
   client  gave  me a comma separated value file (call it x.csv) that has
   an  id  and name and address for about 25,000 people (25,000 records).
   I used read.table to read it, but then discovered that there are stray
   carriage returns on several records.  This plays havoc with read.table
   since it starts a new input line when it sees the carriage return.  In
   short, the read is all wrong.
   I thought I could write a simple function to parse a line and write it
   back  out,  character by character.  If a carriage return is found, it
   would  simply  be  ignored on the writing back out part.  But how do I
   identify a carriage return?  What is the code or symbol?  Is there any
   easier  way  to  rid the file of carriage returns in the middle of the
   input lines?
   Any help is appreciated.
   Walt Paczkowski

   _________________________________
   Walter R. Paczkowski, Ph.D.
   Data Analytics Corp.
   44 Hamilton Lane
   Plainsboro, NJ  08536
   (V) 609-936-8999
   (F) 609-936-3733


More information about the R-help mailing list