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)
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)
Using the make.names() function from the built in base package may help:
You might be looking for the discussion from
?make.names
:In the help file itself, there's a link to a list of reserved words, which are:
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.
The following may not directly address your question but is of great help. Try the
exists()
command to see if something already exists and this way you know you should not use the system names for your variables or function. Example...Almost NONE! You can use 'assign' to make ridiculous variable names:
Yes, that's a variable called '1'. Digit 1. Luckily it doesn't change the value of integer 1, and you have to work slightly harder to get its value:
The "syntactic restrictions" some people might mention are purely imposed by the parser. Fundamentally, there's very little you can't call an R object. You just can't do it via the '<-' assignment operator. "get" will set you free :)