Re: [Rd] Syntactically valid names

2011-07-06 Thread Hadley Wickham
> 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 be

Re: [Rd] Syntactically valid names

2011-07-06 Thread peter dalgaard
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

Re: [Rd] Syntactically valid names

2011-07-05 Thread Hadley Wickham
> 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: > m

Re: [Rd] Syntactically valid names

2011-07-05 Thread Davor Cubranic
On July 5, 2011 04:59:16 PM Hadley Wickham wrote: > That's not a syntactically valid name - you use backticks to refer to > names that are not syntactically valid. I was too loose in my terminology: I meant that `x prime` is a valid name, but as you said, it is not syntactically valid. Davor __

Re: [Rd] Syntactically valid names

2011-07-05 Thread peter dalgaard
On Jul 6, 2011, at 01:40 , Hadley Wickham wrote: > On Tue, Jul 5, 2011 at 7:31 PM, steven mosher wrote: >> regexp approach is kinda ugly >> http://www.r-bloggers.com/testing-for-valid-variable-names/ > > Hmm, I think that suggests a couple of small bug in make.names: > >> make.names("...") >

Re: [Rd] Syntactically valid names

2011-07-05 Thread Hadley Wickham
> This is without quoting, right? Because "make.names" replaces spaces with > periods, and using quoting I can create syntactically valid names that do > include spaces: > >    `x prime` <- 3 >    ls() That's not a syntactically valid name - you use backticks to refer to names that are not syntact

Re: [Rd] Syntactically valid names

2011-07-05 Thread Davor Cubranic
On June 30, 2011 01:37:57 PM Hadley Wickham wrote: > Is there any easy way to tell if a string is a syntactically valid name? [...] > > One implementation would be: > > is.syntactic <- function(x) x == make.names(x) > > but I wonder if there's a more elegant way. This is without quoting, right

Re: [Rd] Syntactically valid names

2011-07-05 Thread steven mosher
regexp approach is kinda ugly http://www.r-bloggers.com/testing-for-valid-variable-names/ On Tue, Jul 5, 2011 at 3:29 PM, Hadley Wickham wrote: > > I wouldn't expect so. The basic structure might be handled using a regexp > of sorts, but even that is tricky because of the "dot not followed by

Re: [Rd] Syntactically valid names

2011-07-05 Thread Hadley Wickham
On Tue, Jul 5, 2011 at 7:31 PM, steven mosher wrote: >  regexp approach is kinda ugly > http://www.r-bloggers.com/testing-for-valid-variable-names/ Hmm, I think that suggests a couple of small bug in make.names: > make.names("...") [1] "..." > make.names("..1") [1] "..1" and > x <- paste(rep("

Re: [Rd] Syntactically valid names

2011-07-05 Thread Hadley Wickham
> I wouldn't expect so. The basic structure might be handled using a regexp of > sorts, but even that is tricky because of the "dot not followed by number" > rule, and then there's the stop list of reserved words, which would make your > code clumsy whatever you do. > > How on Earth would you ex

Re: [Rd] Syntactically valid names

2011-06-30 Thread peter dalgaard
On Jun 30, 2011, at 22:37 , Hadley Wickham wrote: > Hi all, > > Is there any easy way to tell if a string is a syntactically valid name? > > e.g. > > is.syntactic("X123") > # TRUE > is.syntactic("[[") > # FALSE > > One implementation would be: > > is.syntactic <- function(x) x == make.names(