isPrimitveGeneric: Test whether a Primitive Function is an S3 Generic

Description Usage Arguments Details Value Author(s) Examples

Description

Given a primitive function from the base package, or its name, this function carries out an empirical test of whether S3 methods can be written for the primitive and returns TRUE or FALSE accordingly.

Usage

1

Arguments

what

The primitive function or its character string name. Any other object as argument just returns FALSE.

Details

A tentative method for the function is constructed in the global environment, a call is generated with an object having the test class as its class attribute, and the result is compared to the value returned by the method. The method is removed on exit. Since the test is done using tryCatch(), errors just cause FALSE to be returned.

Not all primitives can be tested with 1 or 2 arguments, and some have extra requirements before dispatching. The implementation of this function has a list of special cases. Any updates to that list would be appreciated.

Value

TRUE or FALSE as described.

Author(s)

John M. Chambers

Examples

1
2
3
4
5
6
isPrimitiveGeneric("[") # TRUE
isPrimitiveGeneric(sin) # TRUE
isPrimitiveGeneric(c) # TRUE
isPrimitiveGeneric(split) # FALSE, not a primitive
isPrimitiveGeneric(is.null) # FALSE, methods not recognized
isPrimitiveGeneric(is.numeric) # TRUE

johnmchambers/XRtools documentation built on May 19, 2019, 5:16 p.m.