From pdalgd at gmail.com  Wed Jul  6 10:10:04 2011
From: pdalgd at gmail.com (peter dalgaard)
Date: Wed, 6 Jul 2011 10:10:04 +0200
Subject: [Rd] Syntactically valid names
In-Reply-To: <CABdHhvGAP7+0FeDtyBiKFtdnP6+oAnYjkEUpBQVChY5toVqHCA@mail.gmail.com>
References: <BANLkTimg=TM0hYA1=Obknb+486Hv8T7Fdw@mail.gmail.com>
	<2698F67A-DDF9-4EAF-B7A8-A4FAAE9CCC6B@gmail.com>
	<CABdHhvHmRP6XOkTq+4Z1NjvW1SRwqt1AUwga_ovbMOfi3zi5oA@mail.gmail.com>
	<CAFFLneRp4YY7U+Nn26C+hFhX-4PWaHZMFizBmgEtNg2jjK93qg@mail.gmail.com>
	<CABdHhvEhKGZjSX_fRAAi6_PjHgnhOra_f7w8Y+R8Pw8gGm92OQ@mail.gmail.com>
	<A16B0AB7-C30E-482D-B91A-EC3CC2C70CB9@gmail.com>
	<CABdHhvGAP7+0FeDtyBiKFtdnP6+oAnYjkEUpBQVChY5toVqHCA@mail.gmail.com>
Message-ID: <99993C2E-69F9-4AD9-8484-38C1CF765944@gmail.com>


On Jul 6, 2011, at 03:25 , Hadley Wickham wrote:

>> What's wrong with that? They are names alright, just with special meanings.
> 
> But you can't really use them for variables:
> 
>> ... <- 4
>> ...
> Error: '...' used in an incorrect context
>> ..1 <- 4
>> ..1
> Error: 'nthcdr' needs a list to CDR down
> 
> And make.names generally protects you against that:
> 
>> make.names("function")
> [1] "function."
>> make.names("break")
> [1] "break."
>> make.names("TRUE")
> [1] "TRUE."


That's two different issues:

> y <- list()
> y$... <- 2
> y$..2 <- 3
> y$break <- 4
Error: unexpected 'break' in "y$break"

Notice that there is nothing _syntactically_ wrong with ... & friends as names:

> quote(...<-4)
... <- 4

It's the _evaluator_ that throws the error because the ...-name has a special interpretation.


> 
>>>> x <- paste(rep("x", 1e6), collapse = "")
>>>> x == make.names(x)
>>> [1] TRUE
>> 
>> Mildly insane, but technically OK, no?
> 
> I don't think so:
> 
>> x <- paste(rep("x", 1e6), collapse = "")
>> assign(x, 1)
> Error in assign(x, 1) : variable names are limited to 10000 bytes

But that's a sanity check, with an arbitrary cutoff.  A string of a million "x"s is syntactically a valid name, it's just the evaluator that refuses to play with it. (Not to say that it would be wrong to put in a similar sanity check in make.names.) 

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] Syntactically valid names
peter dalgaard