Open m-muecke opened 5 months ago
.. yeah -- not going to tackle this rn, but seems like the way to go.
vctrs
-Ops for tfb
s --
this should also fix stupid&sloppy behavior like:> x
tfb[3] on (0,1) in basis representation:
using 2 FPCs
1: (0.000,0.77);(0.005,0.79);(0.010,0.74); ...
> x - 2
tfb[3] on (0,1) in basis representation: #BASIS CHANGE SHOULD NOT HAPPEN
using s(arg, bs = "cr", k = 25)
1: (0.000,-1.2);(0.005,-1.2);(0.010,-1.3); ...
> (x - 2) + 2
tfb[3] on (0,1) in basis representation:
using s(arg, bs = "cr", k = 25)
1: (0.000,0.80);(0.005,0.77);(0.010,0.74); ... # NOT THE SAME VALUES AS BEFORE
Currently the math and ops methods are implemented in base R, but there is a interface from vctrs to do it directly: https://vctrs.r-lib.org/reference/vec_math.html, https://vctrs.r-lib.org/reference/vec_arith.html
Here is an example from the bignum package: https://github.com/davidchall/bignum/blob/master/R/vctrs-arith.R#L42 and from the tsibble package: https://github.com/tidyverts/tsibble/blob/main/R/yearmonth.R#L240
and from the docs: https://vctrs.r-lib.org/articles/s3-vector.html