[Rd] 1.9.0-devel: _ in read.delim and make.names
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Thu Mar 4 19:45:37 MET 2004
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)
print(myData$foo.1)
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)
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.
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.
Baz
More information about the R-devel
mailing list