Variable name restrictions in R

Kyle Brandt picture Kyle Brandt · Feb 8, 2012 · Viewed 41.6k times · Source

What are the restrictions as to what characters (and maybe other restrictions) can be used for a variable name in R?

(This screams of general reference, but I can't seem to find the answer)

Answer

joran picture joran · Feb 8, 2012

You might be looking for the discussion from ?make.names:

A syntactically valid name consists of letters, numbers and the dot or underline characters and starts with a letter or the dot not followed by a number. Names such as ".2way" are not valid, and neither are the reserved words.

In the help file itself, there's a link to a list of reserved words, which are:

if else repeat while function for in next break

TRUE FALSE NULL Inf NaN NA NA_integer_ NA_real_ NA_complex_ NA_character_

Many other good notes from the comments include the point by James to the R FAQ addressing this issue and Josh's pointer to a related SO question dealing with checking for syntactically valid names.