This generic provides a common double dispatch mechanism for all infix
operators (`+`

, `-`

, `/`

, `*`

, `^`

, `%%`

, `%/%`

, `!`

, `&`

, `|`

). It is used
to power the default arithmetic and boolean operators for vctrs objects,
overcoming the limitations of the base Ops generic.

vec_arith(op, x, y) # S3 method for default vec_arith(op, x, y) # S3 method for logical vec_arith(op, x, y) # S3 method for numeric vec_arith(op, x, y) vec_arith_base(op, x, y) MISSING()

op | An arithmetic operator as a string |
---|---|

x, y | A pair of vectors. For |

`vec_arith_base()`

is provided as a convenience for writing methods. It
recycles `x`

and `y`

to common length then calls the base operator with the
underlying `vec_data()`

.

`vec_arith()`

is also used in `diff.vctrs_vctr()`

method via `-`

.

`stop_incompatible_op()`

for signalling that an arithmetic
operation is not permitted/supported.

See `vec_math()`

for the equivalent for the unary mathematical
functions.

d <- as.Date("2018-01-01") dt <- as.POSIXct("2018-01-02 12:00") t <- as.difftime(12, unit = "hours") vec_arith("-", dt, 1)#> [1] "2018-01-02 11:59:59 UTC"vec_arith("-", dt, t)#> [1] "2018-01-02 UTC"vec_arith("-", dt, d)#> Time difference of 129600 secsvec_arith("+", dt, 86400)#> [1] "2018-01-03 12:00:00 UTC"vec_arith("+", dt, t)#> [1] "2018-01-03 UTC"vec_arith("+", t, t)#> Time difference of 24 hoursvec_arith("/", t, t)#> [1] 1vec_arith("/", t, 2)#> Time difference of 6 hoursvec_arith("*", t, 2)#> Time difference of 24 hours