locate_function: Locate a function with a given name and return it and its...

Description Usage Arguments Details Value Functions Examples

View source: R/locator.R

Description

These functions first search the given environment, then search all loaded environments, including those where the function is not exported. If found, they return an unambiguous reference to the function.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
locate_function(name, env = globalenv(), ...)

locate_prefixed_function(
  name,
  prefix,
  errname,
  env = globalenv(),
  ...,
  call. = FALSE
)

Arguments

name

a character string giving the function's name.

env

an environment where it should search first.

...

additional arguments to the warning and error warning messages. See Details.

prefix

a character string giving the prefix, so the searched-for function is prefix.name.

errname

a character string; if given, if the function is not found an error is raised, with errname prepended to the error message.

call.

a logical, whether the call (locate_prefixed_function) should be a part of the error message; defaults to FALSE (which is different from stop()'s default).

Details

If the initial search fails, a search using getAnywhere() is attempted, with exported ("visible") functions with the specified name preferred over those that are not. When multiple equally qualified functions are available, a warning is printed and an arbitrary one is returned.

Because getAnywhere() can be slow, past searches are cached.

Value

If the function is found, an unevaluated call of the form ENVNAME:::FUNNAME, which can then be used to call the function even if it is unexported. If the environment does not have a name, or is GlobalEnv, only FUNNAME is returned. Otherwise, NULL is returned.

Functions

Examples

1
2
# Locate a random function in base.
locate_function(".row_names_info")

statnet.common documentation built on June 5, 2021, 5:06 p.m.