r-quantities / units

Measurement units for R
https://r-quantities.github.io/units
175 stars 28 forks source link

Becquerels Show as Hertz #325

Closed tombishop1 closed 2 years ago

tombishop1 commented 2 years ago

When attempting to assign the units Bq, they are only recognised as Hz. I'm guessing this is because they share the same def, 1/s, as they are both measurements of frequency, but they do have subtly different definitions.

set_units(1:5, "Bq") Units: [Hz] [1] 1 2 3 4 5

Enchufa2 commented 2 years ago

Unfortunately, this is how udunits2 works. E.g., with the thinnest wrapper we have around parsing and formatting,

> units:::R_ut_format(units:::R_ut_parse("Bq"))
[1] "Hz"

And this is because Bq is defined as an alias of 1/s, which is already assigned to Hz. You could bring this issue upstream.

tombishop1 commented 2 years ago

Understood, I'll look at the options there. Is there a hack to remove one of entries (e.g. delete Hz) for the duration of a session? I've tried remove_unit(name = "hertz"), but even then set_units(1:5, "Bq") still returns Units: [Hz]. That's odd to me, because set_units(1:5, "Hz") throws an error, as would be expected.

> set_units(1:5, "Hz")
Units: [Hz]
[1] 1 2 3 4 5
> remove_unit(name = "hertz")
> set_units(1:5, "Hz")
Units: [Hz]
[1] 1 2 3 4 5
> set_units(1:5, "Bq")
Units: [Hz]
[1] 1 2 3 4 5
Enchufa2 commented 2 years ago

Yeap, that's odd. This worked for me:

> remove_unit(c("Hz", "Bq"))
> install_unit("Bq", "1/s")
> set_units(1:5, "Bq")
Units: [Bq]
[1] 1 2 3 4 5
tombishop1 commented 2 years ago

Yes, that works for me too, so I guess we can close this for now, and perhaps I'll open an issue upstream. Inspecting udunits2-derived.xml, there is a special entry for "SI derived units with special names and symbols admitted for reasons of safeguarding human health", containing Bq, Gy and Sv. The entry for Bq contains a comment that it is "an alias because 1/s is already mapped to Hz". I'm guessing udunits2 is converting from the alias without considering the exception for human health.