Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement a permil unit with units? #1

Open
sebkopf opened this issue Jan 14, 2025 · 0 comments
Open

implement a permil unit with units? #1

sebkopf opened this issue Jan 14, 2025 · 0 comments

Comments

@sebkopf
Copy link
Contributor

sebkopf commented Jan 14, 2025

units::install_unit("‰", def = "1e-3", name = "permil")
set_units(0.1, "1") |> set_units("‰")
set_units(100, "permil")

It would be nice for formatting in tibbles but maybe a downside is that people would have to always do as.numeric() to pull the value out. Note that we'd probably want just units to avoid the extra dependency.

Note that R is already taken (by roentgen) so defining an isotope ratio would require removal of this unit (which is probably fine in the isovese context):

units::remove_unit("R")
units::install_unit("R", name = "isotope ratio")
set_units(1:5, "R")

But then R/R cannot be defined because it is by definition unitless and we cannot define unitless in different ways (once as permil = 1e-3 and once as permil = (R/R - 1) * 1000. That's essentially 2 different mappings to unitlessness.

doing math with this effectively will only work if we automatically convert dimensionless "units" into numerics and then the arithmetic will work out okay such that people can do set_units(R/R - 1, "permil") but of course that is dimensionless too so should it get converted to just a number? what a mess

alternatively define completely new vctrs that are R, R/R, and permil but then we're basically already at the level of isotopia package which seems too much overhead and sometimes counterintuitive to use

also been thinking about vctrs that have full size units so it's easy to keep track which ratios are actually involve (similar to isotopia) but the overhead gets pretty nasty with none of the speed of dplyr processing. at the end of the day it might just be best to keep it simple and maybe install "R" and "permil" units but nothing else (still the unitless turning into a number i think would be good - KopfLab/chemunits#5) since that would enable easier math with these units

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant