Re: [Rd] Syntactically valid names

From: peter dalgaard <>
Date: Thu, 30 Jun 2011 23:48:12 +0200

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("[[")
> One implementation would be:
> is.syntactic <- function(x) x == make.names(x)
> but I wonder if there's a more elegant way.

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 expect anything to be significantly more elegant than your

function(x) x == make.names(x)

anyway??! (OK, if there was a wrapper for the C level isValidName() function...)

Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email:  Priv:

______________________________________________ mailing list
Received on Thu 30 Jun 2011 - 21:50:28 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 30 Jun 2011 - 22:00:25 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive