[Rd] 1.9.0-devel: _ in read.delim and make.names
wolfram at fischer-zim.ch
Fri Mar 5 09:46:07 MET 2004
--- In reply to: ---
>Date: 04.03.04 18:45 (+0000)
>From: Barry Rowlingson <B.Rowlingson at lancaster.ac.uk>
>To: wolfram at fischer-zim.ch
>Subject: Re: [Rd] 1.9.0-devel: _ in read.delim and make.names
> Wolfram Fischer wrote:
> >In R 1.9.0, make.names will accept "_" as a valid character
> >for a syntactically valid name.
> >I would appreciate to have an option in ``read.delim'' (etc.)
> >that would change "_" in headers of input files to "."
> >for compatibility with code and data written for R 1.8.1 and before.
> Given that you are going to have to change your code to invoke this
> parameter, you may as well just write a 'makeOldStyleNames' function and
> call that.
> For example, suppose you currently have:
> myData = read.table("data.csv",sep=",",head=T)
> and the data file has a column 'foo_1' which has been renamed to foo.1.
> If the option is added to read.table, you'll have to change your code to
> something like:
> myData = read.table("data.csv", sep=",", head=T, oldNames=T)
Another, more precise name for the new argument could be:
> Now that would break in pre-1.9.0 releases. However, if you do:
> myData = read.table("data.csv", sep=",", head=T)
> names(myData) = makeOldStyleNames(names(myData))
> then, as long as makeOldStyleNames doesn't do anything to old style
> (dotted) names, and works in 1.8 and 1.9, you have achieved your goal
> and got back-compatibility as well.
I think that is a good idea and I will use it if there
will be no additional argument for read.delim (etc.).
> The makeOldStyleNames could be quite tricky - just replacing '_' with
> '.' might break if you have 'foo_1' and 'foo.1' in your data frame.
> Perhaps doing the replacement and then calling R's make.names() with
> 'unique=T' will work - depending on what 1.9 does in make.unique.
Thanks - Wolfram
More information about the R-devel