existsFunction(name, generic=TRUE, where, frame=NULL)
where
is supplied, it can either be a number or an object defining
a database.
A number specifies the corresponding element of the search list. For example,
where=2
checks the second database for the existence of the
specified function and returns TRUE if the function is found.
Otherwise,
where
is interpreted as a database of any type.
This database is accessed, but it is not put on the search list.
where
and
frame
.
Returns 'TRUE' if there is a function object with this name. If 'generic == FALSE', then ignore generic functions. This function is useful if you want to check the existence of a function before sourcing a function of the same name. See the example below.
existsFunction("get", where="main") # returns TRUE
## Contents of the file my.fun.q # my.fun <- function(x) { # x * 2 # } # ## check to see if my.fun already exists. ## if not, source the function from the ## file, and then call the function. # if !existsFunction("my.fun") { # source("my.fun.q") # } # my.fun(22)