[R] use of "@" character in variable name

Marc Schwartz marc_schwartz at me.com
Fri Mar 27 02:52:49 CET 2009


On Mar 26, 2009, at 8:40 PM, Rolf Turner wrote:

>
> On 27/03/2009, at 2:04 PM, Mike Miller wrote:
>
>> Importing data with a header row using read.delim, one variable  
>> should be
>> named @5HTT but it is automatically renamed to X.5HTT, presumably  
>> because
>> the "@" is either unacceptable or misunderstood.  I've tried to  
>> find out
>> what the rules are on variable names but have been unsuccessful.   
>> I'll bet
>> someone here can tell me where to look.  Maybe it's hidden away in  
>> here
>> somewhere:
>>
>> http://cran.r-project.org/doc/manuals/R-data.pdf
>
> I don't know if there is a comprehensive list of the rules governing
> variable names but the ``@'' sign is used to access ``slots'' under
> S4 classes and methods.  See ?"@".  So it is (like?) an operation/ 
> operator
> and hence is ruled out just like ``+5HTT'' would be.  Reserved words  
> like
> ``break'' and ``while'' are also excluded.  See fortune(18).
>
> Another rule is that a variable name can't begin with a digit.
>
> And it can't have white space in it.
>
> There are probably other rules, but essentially anything *sensible*
> as a variable name can be used as a variable name.


See ?make.names for more information, which is noted in the  
description of the 'check.names' argument in the read.table() family  
of functions.

HTH,

Marc Schwartz




More information about the R-help mailing list