Skip to content

read.table and strip.white

3 messages · Brian Ripley, Peter Dalgaard

#
On Wed, 31 May 2000, Uwe Ligges wrote:

            
That's tantamount to saying we should not fix bugs because users might be
relying on the undocumented and unintended behaviour!  Yes, changing this
could change things: for a start the V&R MASS datasets would load correctly
on R without R-specific editing.  Does anyone seriously intend to have
heading spaces in their column names in a data frame? Especially as those
are not S variable names, and as you see S-PLUS (but not R) does enforce
that.  (read.table circumvents that by not using the class
constructor, but S-PLUS has an explicit call to make.names lacking in R.)

I am inclined to make the change _and_ to check the column names.

Brian
#
Prof Brian D Ripley <ripley@stats.ox.ac.uk> writes:
I tend to agree, recently having had dealings with an SPSS-created
.cvs file with "Height SDS" and so on as variable names. However, it
would seem that the prototype *does* read the leading whitespace and
replaces it with a dot while fixing the names, no? I don't disagree
that we're probably better off without that effect, but if we're going
for compatibility.
#
On 1 Jun 2000, Peter Dalgaard BSA wrote:

            
No, those are the quotes being converted to `.'  The original example
was

"col1", "col2", "col3"

Now in R the quoting mechanism removes the quotes, but with quote=""
one (now) gets X.col1. etc.  S-PLUS does not have the quoting mechanism,
and leading spaces just disappear (as shown in my original posting).

I've added this in, so now read.table has check.names=TRUE and
strip.white=FALSE arguments, and the header line is always stripped
but only converted if check.names is true.  If you want leading spaces
in the col names, you will need to use quotes and check.names=FALSE,
but you can still do it.