this_function: Capture information about the function above.

Description Usage Arguments Value

View source: R/this_function.R

Description

This function collects information about the function that it's called from, based on the result from sys.status. This function can extract a variety of information, that other functions can piggyback on instead of having to include large chunks of similar code.

Usage

1
this_function(n = 1, details = c(0, 1, 2, 3, 4))

Arguments

n

A positive integer that select which generations to report. The default value 1 selects the parent of this_function, i.e. the function from which it was called. 2 gives the grandparent (needed when this_function is called from within the error-function), and so on. An error will be returned if n is out of range.

details

A value that is compared against the values c(0, 1, 2, 3, 4), which decides the amount of additional information to include as attributes. The default will be to use 0.

Value

This function will return a result that depends on the values of n and details, where the first specifies which function to return whereas the latter one decides the amount of information included as attributes. No attributes will be added when details is given as 0. Higher values of details adds attributes as described below.

info

Attribute added when details is greater than or equal to 1, which is a list that specifies the following details about the function that has been returned: origin, package, status and arguments. The value in origin presents the place where the function was defined, which can be a namespace, the global environment or the name of another function. package is a logical value that is true when origin refers to a package. status will be either exported or internal when the function originates from some package, it will be global if the function was defined in the global environment, it will be local if it was defined in some other function, or it will be unknown if the algorithm couldn't select one of the other ones (this might e.g. happen if a function has been defined in an environment that has been attached to the search-path.

lineage

Attribute added when details is greater than or equal to 2. This is a list having names equal to the functions recorded from the call-stack, and each component of this list contains details as given for the attribute info.

sys.status

Attribute added when details is greater than or equal to 3. A named list that gives the sys.status-information that was used to create the other attributes, see the help-page of sys.parent for the details.

content

Attribute added when details is greater than or equal to 4. A named list that for each occurrence of a function adds a list with a component objects, which gives the content of the functions environment; and a component is_test that holds an array where these components has been tested against the is.<something> tests exported from the namespaces. Note that the result listed here will be the status at the time this_function was called, and that the status of the environments might have changed if it's called at different times within the same target function.


LAJordanger/leanRcoding documentation built on Feb. 27, 2020, 4:42 p.m.