From paul at stat.auckland.ac.nz  Thu Apr 14 02:46:45 2005
From: paul at stat.auckland.ac.nz (paul@stat.auckland.ac.nz)
Date: Thu Apr 14 02:46:53 2005
Subject: [Rd] read.table bug (PR#7789)
Message-ID: <20050414004645.4C0D4CA0A@slim.kubism.ku.dk>

Full_Name: Paul Murrell
Version: 2.1.0 (unsure how long it has been there)
OS: Linux
Submission from: (NULL) (130.216.50.118)
Submitted by: paul



There seems to be a problem with escaped quotes in read.table.
Suppose this is the contents of a text file called "temp.txt" ...

6 'TV2  Shortland Street'
2 'I don\'t watch TV at 7'
1 'I\'m not bothered, whatever that looks good'
2 'I channel surf'

> x <- read.table("temp.txt")
> x
  V1                                         V2
1  2                             I channel surf
2  6                      TV2  Shortland Street
3  2                      I don't watch TV at 7
4  1 I'm not bothered, whatever that looks good
5  2                             I channel surf

(what is "I channel surf" doing as the first row?!)

Problem goes away if I use \" instead of \' or if I leave it as \' and change
the outer quotes from single to double.  e.g. ...

2 "I don\'t watch TV at 7" 

Analysis from Brian Ripley:

The problem is that readTableHead does not handle embedded quotes and so thinks
there are three lines on that file.  See the comment in scan.c

/* <FIXME>  This does not handle escaped quotes, nor does it appear to
   use the blank.lines.skip arg */


[Rd] read.table bug (PR#7789)
paul@stat.auckland.ac.nz