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

Object concept #5

Open
billdenney opened this issue May 8, 2024 · 0 comments
Open

Object concept #5

billdenney opened this issue May 8, 2024 · 0 comments

Comments

@billdenney
Copy link

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"))

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:

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?

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