dev branch to finally complete the basic unit handling logic#39
dev branch to finally complete the basic unit handling logic#39
Conversation
…own units in relation to existing units
…y, as this overwrites % itself; we have to create our own unit for it
…es that emerged with the introduction of at% and wt%
…th information on each column, 2. creating the respective constructor functions
…s in the column names
|
What I implemented here so far:
At this point I think it would be very important to test intensively. Overall this seems to be workable, but it's also a bit brittle. We need to know the edge cases, either to address them, or at least to work around them. So the three big ToDos I see right now are:
|
|
Thank you so much, @nevrome, this all looks awesome. I played a bit around with it and it seems to work fine. I lacked the headspace of writing proper tests, sorry. I would expect that the ID column is created by renaming the respective column rather than making a copy of it. Is there a reason for this behaviour? |
|
Found a potential bug: I tried to connect wt% to the udunits so that except at% and oxide% all units can be handled with the package results in (focus on The behavior occurs here, and deactivating this if-statement in the underlying constructor function disables it (because it disables assignment of units in general). I was not able to figure out the reason. I suspected that You have to restart the R session and reload the package to reproduce the bug. It seems that only "load_all()" does not reset the units defined on package load. |
|
I looked at your changes with 2cbbc68...a69aebe - I didn't know that there would be so much special notation to be mapped, but good that you have a solid overview here. I'll look into the bug you describe now. I have the suspicion that I ran into this as well three weeks ago. Looks familiar. |
|
Ok - so I can reproduce your observation and I still vaguely remember that I encountered the same issue. Afaik this has something to do with overwriting the unitless unit without a custom base. That's what you effectively do with Following this issue here, I think there must be a solution. Looking at the help file of
So far I have left the definition of "mass_basis" empty. When I instead set it explicitly to I'm not sure, though, if this covers what you have in mind. You write
But we already handle all units with udunits, even at%. It just has this custom base which makes it sort of incompatible with other units. But that is unavoidable, right? |
|
I added my change in 3255fa2 with some more comments on this mechanism. |
This was imprecise phrasing from my side, sorry. I meant "udunits doing the conversion", i.e. without the need for dedicated conversion functions. And yes, they are unavoidable for these special cases. Thanks! I will look into the details and your commit later today. |
Welcome to the inconsistency of reporting... some are now outdated, some prefer writing with parentheses and others without. I tried to cover them all 🤷 |
Works as intended 😊 |
This would be handy for columns created in functions to be then included in an archchem object.
|
The bug we observed earlier also occurs in |
nevrome
left a comment
There was a problem hiding this comment.
The bug we observed earlier also occurs in unify_concentration_unit... I asume because the function just takes all columns that can be converted. Do you have a more elegant idea than removing columns with relative errors before unit conversion happens in the function?
Well - we decided that wtP is a unitless unit like %. That means both % and wtP will be caught by the select condition in unify_concentration_unit, right?
units::ud_are_convertible(units::deparse_unit(y), "%")
That means unify_concentration_unit will adjust the units of wtP columns and % columns.
I have two questions:
- Was it wise to define
wtPas a unitless unit as I did in my last commit? It seems every conversion from and towtPneeds to be a custom defined operation in the ASTR package, not something that the units package can automatically give us. So maybe we should treat it as something entirely unconnected, likeatP. - Is
unify_concentration_unitill-conceived? ForwtPandatPconversion we decided to implement custom functions. What are the other applications of this functions that really matter? I think originally I wrote this to unify units likeppb,ppm,ppt,%etc.. I feel your understanding of what this function could and should do goes beyond that. Maybe we should delete it and leave these trivial conversions up to the user.
My understanding is that
To me, the relative errors are the odd ones out because they have a different type of total than the other values (the specific value rather than the dataset). Therefore, my suggestion is to convert relative errors to absolute errors during import and to handle by default only absolute errors. Conversion functions between relative and absolute errors should be provided, of course. |
I created this as a development branch for @archaeothommy and me (and whoever would like to join) to work on the archchem class and its missing core features (see e.g. #12, #18, #20).