These generics are inspired by the S3 groupGeneric functions, but use
vec_ptype()
and vec_cast()
to ensure that all inputs are of the same
type. They are also finer grained, additionally dividing up groups by arity
and return type. vec_generic_call()
provides a convenient way to call the
default method of internal generics; this allows you to use existing base
R behaviour where possible.
vec_grp_compare(generic, x, y)vec_grp_logical(generic, x, y)
vec_grp_unary(generic, x)
vec_grp_numeric(generic, x, y)
vec_grp_summary(generic, x, na.rm = TRUE)
vec_generic_call(generic, x, y, ...)
Name of generic function
Vectors. x
and y
will always have the same ptype.
Remove missing values?
Additional arguments passed to generic
.
vec_grp_compare()
and vec_grp_logical()
call the internal method
and return a logical vector. vec_grp_unary()
, vec_grp_numeric()
, and
vec_grp_summary()
will call the internal method, and then recast the
output to the same ptype as x
.
vctrs provides five group generics:
vec_grp_compare()
: ==
, !=
, <
, <=
, >=
, >
vec_grp_logical()
: &
, |
, (unary) !
vec_grp_unary()
: unary +
and -
.
vec_grp_numeric()
: +
, -
, *
, /
, ^
, %%
, %/%
vec_grp_summary()
: all()
, any()
, sum()
, prod()
, min()
,
max()
, range()
`
If your vector is number-y you will generally implement vec_grp_unary()
,
vec_grp_numeric()
, and vec_grp_summary()
. If your vector is truth-y,
you will implement vec_grp_logical()