You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I thought that it would be useful to have a discussion of how the substances object could be created to make best use of existing code in units and also the need for substances.
For that, I looked at what units uses for both the units and mixed_units objects:
library(units)
#> udunits database from C:/Users/wdenn/AppData/Local/R/win-library/4.3/units/share/udunits/udunits2.xml
dput(units::set_units(1, "km"))
#> structure(1, units = structure(list(numerator = "km", denominator = character(0)), class = "symbolic_units"), class = "units")
units_options(allow_mixed=TRUE)
dput(c(units::set_units(1, "km"), units::set_units(1, "kg")))
#> structure(list(structure(1, units = structure(list(numerator = "km", #> denominator = character(0)), class = "symbolic_units"), class = "units"), #> structure(1, units = structure(list(numerator = "kg", denominator = character(0)), class = "symbolic_units"), class = "units")), class = c("mixed_units", #> "list"))
A light cleanup of the dput representation of the mixed_units class looks like this:
structure(list(
structure(1, units = structure(list(numerator = "km", denominator = character(0)), class = "symbolic_units"), class = "units"),
structure(1, units = structure(list(numerator = "kg", denominator = character(0)), class = "symbolic_units"), class = "units")),
class = c("mixed_units", "list")
)
For my use cases, the base assumption is that most or all vectors of substances would have different substances per vector element (e.g. c(set_substance(1, "mol", "hydrogen"), set_substance(1, "g", "helium")) would be my typical use case. So, I would lean toward the base case being separate substances per item rather than one substance used throughout.
Building on that, my preference would be that we then use a structure almost identical to the units structure for a substances object:
structure(1, units = structure(list(numerator = "mol", denominator = character(0)), class = "symbolic_units"), substance = "hydrogen", class = "substance")
The only two differences between the units and proposed substance structure are adding an attribute named substance with the substance name and the class being substance.
How does that sound?
The text was updated successfully, but these errors were encountered:
I thought that it would be useful to have a discussion of how the
substances
object could be created to make best use of existing code inunits
and also the need forsubstances
.For that, I looked at what
units
uses for both theunits
andmixed_units
objects:Created on 2024-05-08 with reprex v2.1.0
A light cleanup of the dput representation of the mixed_units class looks like this:
For my use cases, the base assumption is that most or all vectors of
substances
would have differentsubstances
per vector element (e.g.c(set_substance(1, "mol", "hydrogen"), set_substance(1, "g", "helium"))
would be my typical use case. So, I would lean toward the base case being separate substances per item rather than one substance used throughout.Building on that, my preference would be that we then use a structure almost identical to the
units
structure for asubstances
object:The only two differences between the
units
and proposedsubstance
structure are adding an attribute namedsubstance
with the substance name and the class beingsubstance
.How does that sound?
The text was updated successfully, but these errors were encountered: