Search for a S-PLUS Function

DESCRIPTION:

Searches for a S-PLUS function and returns a logical stating whether the function exists. You can specify the position to search.

USAGE:

existsFunction(name, generic=TRUE, where, frame=NULL)

REQUIRED ARGUMENTS:

name
character string giving the name of the function.

OPTIONAL ARGUMENTS:

generic
indicates whether to include generic functions in the search.
where
database from which the function should come. If 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.
frame
specifies which of the current frames the evaluation should be searched.

It is an error to supply both where and frame.

VALUE:

returns TRUE or FALSE according to whether the search succeeds.

DETAILS:

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.

SEE ALSO:

, , , , , , , , , , , .

EXAMPLES:

 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)