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

pull out core functionality into separate package "chemunits" #1

Open
sebkopf opened this issue Dec 5, 2018 · 1 comment
Open

pull out core functionality into separate package "chemunits" #1

sebkopf opened this issue Dec 5, 2018 · 1 comment

Comments

@sebkopf
Copy link
Collaborator

sebkopf commented Dec 5, 2018

make a separate package for core chemical units and keep microbialkitchen to be primarily media recipes, carbonate chemistry, etc.

@sebkopf sebkopf changed the title pull out core functionality into chemtools pull out core functionality into chemunits Jan 8, 2025
@sebkopf sebkopf changed the title pull out core functionality into chemunits pull out core functionality into separate package "chemunits" Jan 8, 2025
@sebkopf sebkopf changed the title pull out core functionality into separate package "chemunits" pull out core functionality into separate package "biochemunits" Jan 8, 2025
@sebkopf
Copy link
Collaborator Author

sebkopf commented Jan 8, 2025

added units:

  • M (molarity)
  • Da (Dalton)

consider making this into a broader package that also includes some biochem and geochem units like:

package definition: chem units are autoscaled to the best SI prefix

also make sure to provide easy to set options for the autoscaling of prefixes and conversion to default units (see how units sets the options)

  • in package: define default units for different quantity types (temperature, pressure, etc.) and set whether to auto scale to base unit and to best prefix when this quantity pops up (i.e. a tibble with these information that can be updated with a config function), maybe define_cu_types(type, default_unit = NULL, auto_to_default_unit = NULL, auto_to_best_prefix = NULL) function

overall functions:

  • set_cu(x, units, to_default_unit = T/F/auto(), to_best_prefix = T/F/auto()) --> for a specific unit can use units::set_units() directly but not sure that needs to be exported (maybe good though to do so). The defaults should be auto. Even when calling qty on a qty object, the default is auto which may seem silly but keeps the behaviour consistent that if people really want a specific unit, they MUST set to_default_unit = FALSE and/or to_best_prefix = FALSE --> if something is not a recognized cu type then just the base unit conversion doesn't happen but everything else does
  • note: the units param should also accept the output from units::units()
  • get_unit_type() --> will return if something is "temperature", "pressure", etc. by checking whether it can be converted to the type's base unit via units::ud_are_convertible(), returns NA if doesn't match a defined type
  • maybe (probably redundant): get_cu_units() --> units:::units.units() |> paste()
  • cu_get_value(qty, units = cu_units(qty)) --> basically scaling + numeric
  • define_cu_types() / get_cu_types() --> see above to change the package options. Note make sure that none of the types can be interconverted to each other otherwise they are not unique.
  • internal: get_default_units() --> get default units (only if get_cu_type works)
  • convert_to_default_units.units/.chemunits() --> converts to the default unit defined in the package options, warning if not a cu object
  • scale_to_best_prefix() --> this should only ever change the prefix! not the unit that's used, could potentially migrate to units package
  • make_units_explicit(...) - warning that mixed units are ignored; the ... are parameters that are temporarily used for units_options(...), potentially migrate to units package

--> with the cu class need to change all the arithmetic functions to apply the default unit/best prefix conversions as defined

NOTE: the concept of a base unit is also discussed in a long running units issue but it's not exactly the same as the idea here is that depending on people's chemical systems they may want to choose different default units for different types of units --> maybe this is something that could actually be incorporated into units

@sebkopf sebkopf changed the title pull out core functionality into separate package "biochemunits" pull out core functionality into separate package "chemunits" Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant