The custom mass set will be available in subsequent calls of get_mass(). You may specify masses of selected elements only. In this case, however, calculating the mass of a formula that contains an element whose mass was not specified will return NA.

new_mass_set(masses, inherits_from = NULL)

Arguments

masses

Named numeric vector of the form c(element_1 = mass_1, ..., element_n = mass_n).

inherits_from

Mass set from which masses should be inherited if they are not specified in masses. Either "average", "monoisotopic" or a variable containing a mass set previously defined by new_mass_set().

Value

A named numeric vector containing supplied and inherited element masses.

See also

get_mass() for calculating molecular masses, atomic_masses for predefined mass sets "average" and "monoisotopic"

Examples

my_masses <- new_mass_set(c(H = 10, C = 100, O = 1)) molecular_formula("C6 H8 O5") %>% get_mass(my_masses)
#> [1] 685
# returns NA since my_masses does not specify the mass of sulfur molecular_formula("H2 S O4") %>% get_mass(my_masses)
#> [1] NA
# inherit masses from another mass set to provide default values my_masses_complete <- new_mass_set( c(H = 10, C = 100, O = 1), inherits_from = "average" ) molecular_formula("H2 S O4") %>% get_mass(my_masses_complete)
#> [1] 56.06