From wolfram at fischer-zim.ch  Fri Mar  5 09:46:07 2004
From: wolfram at fischer-zim.ch (Wolfram Fischer)
Date: Fri Mar  5 09:45:23 2004
Subject: [Rd] 1.9.0-devel: _ in read.delim and make.names
In-Reply-To: <40477951.5080204@lancaster.ac.uk>
References: <20040304153628.GA22389@s1x.local>
	<40477951.5080204@lancaster.ac.uk>
Message-ID: <20040305084607.GA2622@s1x.local>

--- In reply to: ---
>Date:    04.03.04 18:45 (+0000)
>From:    Barry Rowlingson <B.Rowlingson@lancaster.ac.uk>
>To:      wolfram@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)
>  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)

Another, more precise name for the new argument could be:
``allow.underscores''.

> 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.
> 
> Baz

Thanks - Wolfram


[Rd] 1.9.0-devel: _ in read.delim and make.names
Wolfram Fischer