prettyunits icon indicating copy to clipboard operation
prettyunits copied to clipboard

Add {units} compatibility with majority-vote for best units

Open cregouby opened this issue 5 years ago • 3 comments

This is an opinionated PR to make pretty_num work with class("units") number. I'm not confortable with the package dependencies impact. I think it would be much cleaner to turn both impacted functions into S3 methods and split the "units::" part of this P.R. into a P.R. to the {units} team

cregouby avatar Nov 09 '20 13:11 cregouby

Codecov Report

Merging #28 (0349006) into master (b1cdad8) will increase coverage by 5.24%. The diff coverage is 79.03%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #28      +/-   ##
==========================================
+ Coverage   65.26%   70.51%   +5.24%     
==========================================
  Files           4        5       +1     
  Lines          95      156      +61     
==========================================
+ Hits           62      110      +48     
- Misses         33       46      +13     
Impacted Files Coverage Δ
R/numbers.R 78.33% <78.33%> (ø)
R/sizes.R 18.42% <100.00%> (+2.20%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b1cdad8...0349006. Read the comment docs.

codecov-io avatar Nov 15 '20 10:11 codecov-io

Thanks! I updated this, so it could be merged. However, it would be great to drop the hard dependency on units.

Maybe we can move it to Suggests?

Also, the current implementation fails, because it seems that we cannot compare 'units' objects and regular numbers any more:

library(units)
l_cm <- set_units(1337129, cm)
pretty_num(l_cm)
#> Error in Ops.units(amt, as.integer(amt)) :
#>   both operands of the expression should be "units" objects

l_cm < 0
#> Error in Ops.units(l_cm, 0) :
#>   both operands of the expression should be "units" objects

gaborcsardi avatar Sep 24 '23 09:09 gaborcsardi

I'll have a look this week on it...

cregouby avatar Sep 24 '23 20:09 cregouby