Learn R Programming

covtracer (version 0.0.2)

srcrefs: Retrieve srcrefs

Description

This function takes a code collection and returns a list of related srcref objects with list names that associate the srcref with a name or alias that could be used to find documentation. Code collections include structures such as package namespaces, environments, function definitions, methods tables or class generators - any object which enapsulates a single or set of srcref objects.

Usage

srcrefs(x, ...)

# S3 method for default srcrefs(x, ..., srcref_names = NULL, breadcrumbs = character())

# S3 method for list srcrefs(x, ..., srcref_names = NULL, breadcrumbs = character())

# S3 method for namespace srcrefs(x, ..., breadcrumbs = character())

# S3 method for environment srcrefs(x, ..., breadcrumbs = character())

# S3 method for R6ClassGenerator srcrefs(x, ..., srcref_names = NULL, breadcrumbs = character())

# S3 method for standardGeneric srcrefs(x, ..., srcref_names = NULL)

# S3 method for nonstandardGenericFunction srcrefs(x, ..., srcref_names = NULL)

# S3 method for MethodDefinition srcrefs(x, ..., srcref_names = NULL)

Value

A list of srcref objects. Often, has a length of 1, but can be larger for things like environments, namespaces or generic methods. The names of the list reflect the name of the Rd name or alias that could be used to find information related to each srcref. Elements of the list

will have attribute "namespace" denoting the source environment namespace if one can be determined for the srcref object.

Arguments

x

An object to source srcrefs from

...

Additional arguments passed to methods

srcref_names

An optional field used to supercede any discovered object names when choosing which names to provide in the returned list.

breadcrumbs

Recursive methods are expected to propegate a vector of "breadcrumbs" (a character vector of namespace names encountered while traversing the namespace used as a memory of what we've seen already), which is used for short-circuiting recursive environment traversal.

Details

For most objects, this is a one-to-one mapping of exported object names to their srcref, just like you would get using getNamespace(). However, for classes and methods, this can be a one-to-many mapping of related documentation to the multiple srcrefs that are described there. This is the case for S3 generics, S4 objects and R6 objects.

Objects without any related srcrefs, such as any datasets or objects created at package build time will be omitted from the results.

Examples

Run this code
# examples use `with` to execute within namespace as function isn't exported
ns <- getNamespace("covtracer")

# load and extract srcrefs for a package
with(ns, srcrefs(getNamespace("covtracer")))

# extract srcrefs for functions
with(ns, srcrefs(srcrefs))

Run the code above in your browser using DataLab