Learn R Programming

debug (version 1.1.0)

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, but this isn't checked or required). Used by mtrace.

Usage

fun.locator( fname, from=.GlobalEnv)

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

Value

  • A list of environments where 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. 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. I don't know what happens with S4-style methods.

See Also

getAnywhere