Several months ago I asked something similar, but I was using JavaScript to check if provided string is a \"valid\" R object name. Now I\'d like to achieve the same by using
As Josh suggests, make.names is probably the best solution to this. Not only will it handle weird punctuation, it'll also flag reserved words:
make.names
make.names(".x") # ".x" make.names("_x") # "X_x" make.names("if") # " if." make.names("function") # "function."