Learn R Programming

boostr (version 1.0.0)

isClassConstructor: check if a function is a(n S3) class constructor

Description

takes a function and returns a boolean indicating whether its output gets assigned a class.

Usage

isClassConstructor(func)

Arguments

func
any function

Value

a boolean. If the return value is TRUE the boolean has attribute classes which returns the (potential) classes for the output of func

Details

The body of func is search for one of three idioms:
  1. UseMethod("className")
  2. class(output) <- classes
  3. attr(output, "class") <- classes

If either is found, the assigned class (or classes) are returned as the classes attribute of the output. If none are found, a value of FALSE is returned (with no attributes).

Examples

Run this code
isClassConstructor(mean) # FALSE

# simple output
library(randomForest)
isClassConstructor(randomForest) # TRUE

# complicated output (multiple values in "classes")
isClassConstructor(glm) # TRUE
isClassConstructor(lm) # TRUE

Run the code above in your browser using DataLab