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

Share:

Description

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

Usage

1

Arguments

func

any function

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).

Value

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

Examples

1
2
3
4
5
6
7
8
9
isClassConstructor(mean) # FALSE

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

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

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.