debug (version 1.3.1)

fun.locator: Get environment(s) where an object exists.

Description

Checks the frame stack, the search list, any namespaces, and any S3 method tables for copies of an object (normally a function). Used by mtrace. If the search starts from a reference-class object, only the object itself is searched, and legit methods are forced into existence.

Usage

fun.locator( fname, from=.GlobalEnv, mode='function')

Arguments

fname
character string (the object's name)
from
Where to start looking:either an environment, another function (in which case, that function's defining environment is used), or a frame number. 0 is treated as .GlobalEnv
mode
What type of object to look for-- by default, a function. Set to any if the object's mode is not relevant.

Value

fname was found, of length 0 if no copies were found. First, any environments between from and topenv( from) are searched (normally, this means temporary frames wherein fname could have been defined; but see Details). Next, the search list is checked. Next, all loaded namespaces are checked. Finally, all S3 method tables are checked.

Details

When fname is defined in a namespaced package foo, several copies will exist at once. If foo exports fname, then fname will be found both in the search path (in package:foo) and in the "hidden" environment asNamespace( "foo"). The first version will be found by "normal" calls to fname, but the hidden version will be found whenever fname is invoked by a function in package:foo. If the S3 method somegeneric.fname is defined in package:foo, then it will exist both in asNamespace("foo") and in get( ".__S3MethodsTable__.", asNamespace( "foo")), although not in the main search path. If fname is both exported and an S3 method, then there will be three copies. Other packages that import from package foo may also have fname in the parent environments of their namespaces. All such duplicates should probably be identical, and if you want to change any one copy, you probably want to change all of them.

Normally, the search path environment(s) where fname is found will be given before (i.e. with lower index than) the hidden namespace environment. However, if from is used to start the search in a hidden namespace environment where fname exists, then the hidden namespace will be returned first. Duplicated environments are removed from the return list.

For reference-class and S4 methods, you need to set from explicitly; see ?mtrace and package?debug respectively.

See Also

getAnywhere