[R] Determining if an object name does not exist

Duncan Murdoch murdoch.duncan at gmail.com
Sat Jan 14 11:57:11 CET 2012


On 12-01-14 5:47 AM, Ajay Askoolum wrote:
> Is there a way to tell whether an object name 1. is valid 2. is not going to cause a collision with an existing object by the same name?

For 1, you could put your names in a character vector x, then check 
whether x and make.names(x) are identical; if so, x contains 
syntactically valid names.  (Do remember that almost anything can be a 
name if you put it in back quotes.)

For 2, you could check exists(x) to find if objects with those names exist.

Duncan Murdoch



More information about the R-help mailing list