vec_math | R Documentation |
Math operations implementations. Note that these strip stype attributes, e.g. context.
## S3 method for class 'v_count' vec_math(.fn, .x, ...) ## S3 method for class 'v_continuous' vec_math(.fn, .x, ...) ## S3 method for class 'v_binary' vec_math(.fn, .x, ...)
.fn |
A mathematical function from the base package, as a string. |
.x |
A vector. |
... |
Additional arguments passed to |
vctrs implements a Math
method which has the effect of any math operator
being called for a subclasses of vctrs_vct
being dispatched to
vctrs::Math.vctrs_vctr
. That method then calls the generic
vctrs::vec_math
so by creating a method for this class we prevent the
dispatch from falling through to vec_math.default
. We need to create our
own definitions for these math operators since vec_math.default
has the
effect of invoking the appropriate operator in the base package with the raw
data as the input (for vctrs types that are supported), and then restoring
the appropriate vctrs type but not stype type (for vctrs types that are not
supported an error is thrown immediately).
Further note that vctrs also implements Summary.vctrs_vctr
which routes to
the vctrs::vec_math
generic so we can include operators in that group in
this function as well.
See the groupGeneric
documentation or
https://adv-r.hadley.nz/s3.html#group-generics for more details.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.