[R] read.table: check.names arg - feature request

Marc Schwartz MSchwartz at medanalytics.com
Thu Sep 4 20:07:55 CEST 2003


On Thu, 2003-09-04 at 12:00, Vadim Ogranovich wrote:
> I admit I should have been more clear in my original posting. Let me
> try again (and I do know that by deafulat read.table discards
> everything after '#' which is why I use comment.char="", my bad not to
> mention this).
> 
> 
> Here is a typical example of my data file:
> 
> #key	value
> foo	1.2
> boo	1.3
> 
> As you see the header line begins with '#' and then lists the column
> names, however make.names will convert the raw names  c("#key",
> "value") to c(".key", "value") while I need c("key", "value"), i.e. no
> dot before key. So I am asking to give us a hook to specify the
> function that will handle this situation.
> 
> 
> 
> I am not sure I understand how having this hook can result in an
> invalid data frame? It can return invalid names, but check.names=FALSE
> can too.
> 
> Thanks,
> Vadim

SNIP 

What's wrong with changing the colnames after the import:

(This is under R 1.7.1 under RH 9, using defaults)

# Note the conversion of the '#' to 'X.'
make.names(c("#key", "value"))
[1] "X.key" "value"

# Presuming you have dataframe 'df' now imported:
colnames(df)
[1] "X.key" "value"

# Now change them
colnames(df) <- gsub("X\\.", "", colnames(df))

# Check names
colnames(df)
[1] "key"   "value"



Is there a reason that you could not do this after, rather than before
or during the import? You are asking R Core to make a substantive change
to a function, when an alternative already exists to resolve a rather
unique situation.

HTH,

Marc Schwartz




More information about the R-help mailing list