exists
Determine if an Object is Defined

Description

Looks for an object with the given name to check whether it has been defined.

Usage

exists(x, where = -1, envir = if (missing(frame)) as.environment(where)
    else sys.frame(frame), frame, mode = "any", inherits = TRUE)

Arguments

x a character string representing the object to be found.
where specifies the environment in which to find the object. exists accepts several ways to specify the environment. See Details for more information.
envir an alternative way to specify the environment to find the object.
frame a frame used in calling list. If provided, the default value of envir is set to sys.frame(frame).
mode a character string giving the mode wanted for the object. The default, "any", means that any mode is acceptable.
inherits a logical flag. If TRUE (the default), specifies searching parent frames. Normally, only the current frame, the global frames, and databases are searched for an object.

If inherits=TRUE, the parent frame of the current frame, its parent frame, and all further ancestors are searched.

Details

To specify the environment in which to find the object, you can specify where as: If mode is provided but not set to the default value of "any", then only the specified type is sought.
Value
returns a logical value to indicate if the target object is found corresponding to the given name, mode, environment and other requirements.
References
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
See Also
get
Examples

exists("CO2", where="package:stats") # [1] TRUE

exists("CO2", where=2) # [1] TRUE

Package base version 4.0.0-28
Package Index