r-quantities / units

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

ud_is_parseable not exported? #222

Closed bergsmat closed 4 years ago

bergsmat commented 4 years ago

ud_is_parsable() is mentioned in the help for as_units(), but appears not to be exported. Probably a typo for ud_is_parseable(), also not exported. Can you confirm? I suggest exporting, as this would be very useful at my end.

Enchufa2 commented 4 years ago

Yes, it's a typo; and no, it's not exported. What's your use case?

I'm not sure this is a good idea. For sure, units tries to stick to udunits' capabilities as much as possible, but still units is a different abstraction that uses udunits as the backend, and thus it should be more than determining whether an expression is parseable or not by udunits. Instead, as_units resolves what is or what is not supported by units, not ud_is_parseable, and, IMO, references to ud_is_parseable should be dropped from the manual.

bergsmat commented 4 years ago

Ok, I think I understand now. Maybe not a good idea to export.

My use case can be described two ways: I need to check whether a string provided by the user qualifies as 'units'; and I need to promise my users that if they provide a unit string in a 'standard' format that it will be honored. Right now, my definition of 'standard' is operational: if units::as_units() does not return an error, we're good. But you see the problem: I'm calling as_units() just to see if it breaks, and I'm feeling like maybe there is something more fundamental like is_units() that would serve as a cleaner implementation. I think I saw that you are calling ud_is_parseable() internally, but you may wish to change that in the future. So for now, maybe best path for me is to wrap as_units() in a local is_parseable() or similar.

Enchufa2 commented 4 years ago

Yes, the best way to proceed is exactly as you say: checking whether as_units succeeds, because that's what we would do anyway if we export some kind of is_parseable. And something like is_units would be equivalent to inherits(x, "units"), which is not what you want.

Closing this then. Thanks!