is_s3_generic: Is the input an S3 generic or method?

Description Usage Arguments Value References See Also Examples

View source: R/is-function.R

Description

Checks whether the input is an S3 generic or method.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
assert_is_s3_generic(x, severity = getOption("assertive.severity", "stop"))

assert_is_s3_method(x, severity = getOption("assertive.severity", "stop"))

assert_is_s3_primitive_generic(x, severity = getOption("assertive.severity",
  "stop"))

assert_is_s3_group_generic(x, severity = getOption("assertive.severity",
  "stop"))

assert_is_s4_group_generic(x, severity = getOption("assertive.severity",
  "stop"))

assert_is_s3_internal_generic(x, severity = getOption("assertive.severity",
  "stop"))

is_s3_generic(x, .xname = get_name_in_parent(x))

is_s3_method(x, .xname = get_name_in_parent(x))

is_s3_primitive_generic(x, .xname = get_name_in_parent(x))

is_s3_group_generic(x, .xname = get_name_in_parent(x))

is_s4_group_generic(x, groups = c("Arith", "Compare", "Ops", "Logic", "Math",
  "Math2", "Summary", "Complex"), .xname = get_name_in_parent(x))

is_s3_internal_generic(x, .xname = get_name_in_parent(x))

Arguments

x

Input to check.

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

.xname

Not intended to be used directly.

groups

A character vector of S4 group generic groups.

Value

is_internal_function returns TRUE when the input is a closure function that calls .Internal. The assert_* function returns nothing but throw an error if the corresponding is_* function returns FALSE.

References

is_s3_generic is based upon is_s3_generic. Similarly, is_s3_method is based upon find_generic, internal to pryr, with some ideas from isS3method. is_primitive_generic checks for the functions listed by .S3PrimitiveGenerics. is_s3_group_generic checks for the functions listed by .get_internal_S3_generics, internal to the tools package. is_s4_group_generic checks for the functions listed by getGroupMembers. S4 group generics are mostly the same as S3 group generics, except that the not operator, !, is S3 group generic but not S4, and log2 and log10 are S4 group generic but not S3. is_s3_internal_generic checks for the functions listed by .get_internal_S3_generics, internal to the tools package. internal_generics, internal to pryr works similarly, though checks for S4 group generics rather than S3 group generics. There is some discussion of group generics scatterd throughout R-internals. In particular, see the section on the Mechanics of S4 Dispatch. https://cran.r-project.org/doc/manuals/r-devel/R-ints.html#Mechanics-of-S4-dispatch

See Also

is.function and its assertive wrapper is_function. is_closure_function to check for closures/builtin and special functions. is_internal_function to check for functions that use the .Internal interface to C code.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# General check for S3 generics and methods
is_s3_generic(is.na)
is_s3_method(is.na.data.frame)

# More specific types of S3 generic
is_s3_primitive_generic(c)
is_s3_group_generic(abs)
is_s3_internal_generic(unlist)

# S4 group generics are mostly the same as S3 group generics
is_s4_group_generic(cosh)

# Renaming functions is fine
not <- `!`
is_s3_group_generic(not)

# Some failures
assertive.base::dont_stop({
assert_is_s3_primitive_generic(exp)
assert_is_s4_group_generic(`!`)
})

assertive.types documentation built on May 1, 2019, 10:31 p.m.