vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

Can `vec_math()` implement `round()` and `signif()`?

Open davidchall opened this issue 3 years ago • 1 comments

Reading around this topic, it appears round() and signif() can either be implemented via the Math S3 group generic or the Math2 S4 group generic. {vctrs} implements the S3 generic via vec_math(): https://github.com/r-lib/vctrs/blob/faccc3aa6d8772a8cbc32b1d254b745685d3c4ff/R/type-vctr.R#L555-L558

However, the documented list of functions supported by vec_math() appears to be those supported by the Math S4 group generic (which excludes round() and signif()): https://github.com/r-lib/vctrs/blob/5eecfee07c6b231f29358b6883cee4c9e7f24576/R/numeric.R#L16-L22

Please can you clarify if vec_math() should be used to implement round() and signif()? Initial testing shows that it works, but I'm not sure if there are any caveats (e.g. how to pass additional arguments)?

davidchall avatar Jun 10 '21 14:06 davidchall

I see round and signif mentioned in ?groupGeneric. Source location: https://github.com/r-devel/r-svn/blob/ecff5c591f8b1cfa80c0055c1c6da430481e804b/src/main/arithmetic.c#L1589-L1590 .

I suspect you'll be seeing the extra arguments in the ellipsis, does it work when you add them to the signature?

Perhaps we should add pointers to the documentation.

krlmlr avatar Oct 31 '21 06:10 krlmlr