tidywater 0.11.0
New features
- Changes to existing functions
-
chemdose_toc()gains reuse-water models from Wilder & Korak (2025) for aluminum coagulants. -
biofilter_toc()gains reuse and ATP-based models from Peterson & Summers (2021) and Terry et al. (2024). -
chemdose_ph()now supports polyaluminum chloride and citric acid.chemdose_toc()now supports ACH and PACl. -
define_water()gainsno2(nitrite, mg/L as N) andtot_citric(citric acid) arguments. - The
waterclass gains aco2slot (dissolved CO2, H2CO3*, in mg/L as CO2). It is calculated fromh2co3. -
convert_units()supports mg/L as P and mg/L as Cl2. Start and end units and formulas allow for “close enough” spellings (eg; case insensitive, with or without spaces and slashes, etc).formulais optional when converting within the same unit type (e.g. mg/L to g/L).
-
- New functions
-
scavenge_oh()calculates the background OH radical scavenging term for UV/AOP. -
chemdose_inorgdemand()calculates the free chlorine residual after the inorganic chlorine demand of Mn, Fe, and ammonia. -
check_water()contains many of the warnings that were previously included indefine_water(). The warnings were cumbersome and often ignored, so this function provides a way to deliberately evaluate how a water quality is defined. -
convert_flow()for unit conversions involving flow rates. -
define_chemical()function and newchemicalclass are the starting point for better units handling of chemicals, but are not yet incorporated into other functions.
-
Breaking changes
- API changes
-
chemdose_ph_df()and the otherchemdose_*_df()functions gainkeep_dose_cols(defaultFALSE), which drops the dose columns from the output to prevent double dosing downstream. -
solvemass_solids()has been revamped - both inputs and outputs have changed and the underlying calculation is now based directly on stoichiometry. -
regulate_toc()has been revamped - both inputs and outputs have changed.
-
- Major calculation changes
-
convert_units()now correctly converts through moles of the formula, which changes some results: mg/L as CaCO3 to or from M or eq/L now uses the formula’s charge. Monovalent ions were previously off by a factor of 2 (e.g. 50 mg/L as CaCO3 of HCO3 is now 1 mM, not 0.5 mM). Divalent conversions like hardness and alkalinity are unchanged. mg/L as N counts N atoms per formula, so (NH4)2SO4 is 2 N. -
define_water()now warns and sets carbonate species to 0 whenalkis less than the non-carbonate alkalinity (e.g. hydroxide at high pH). Previously, negative carbonate alkalinity could be carried through. Argumenttot_bo3is nowtot_bo4, and thebo3andtot_bo3slots are replaced byh3bo3,h4bo4, andtot_bo4. - Kw is now calculated consistently with
K_temp_adjust()using the van ’t Hoff equation, assuming a constant enthalpy of 55,830 J/mol for H2O -> H+ + OH-. It previously used a rounded empirical formula; pH results change slightly at temperatures other than 25 C. -
chemdose_chloramine()previously stored free ammonia in thetot_nh3slot. The slot now correctly holds total ammonia. -
chemdose_chlordecay()withuse_chlorine_slot = TRUEnow reads the chlorine slot as Cl2, not Cl, so the slot counts at its full value. The free chlorine residual is also clamped at 0 and no longer goes negative. -
solvect_chlorine()now correctly converts thefree_chlorineslot from mol/L to mg/L as Cl2 whenfree_cl_slot = "slot_only"or"sum_with_residual". CT was previously about 5 orders of magnitude too low. -
dissolve_cu()now correctly uses orthophosphate in mg/L as PO4; it previously used mol/L, so orthophosphate had almost no effect. Results with orthophosphate are now lower (e.g. 2 mg/L PO4 lowers copper by about 33%). -
gacbv_toc()now correctly looks up bed volume at C/C0 =target_doc / doc.
-
- Minor calculation changes and edge cases
-
balance_ions()now includes Fe, Al, Mn, F, and Br. -
chemdose_ph()now accounts for borate and silicate. -
solveresid_o3()returns 0 instead of a negative residual when ozone demand exceeds the dose, sosolvect_o3()no longer returns negative CT. -
gacrun_toc(),gac_toc(), andgacbv_toc()now use influent DOC, not TOC. Both the Zachman and WTP models are written in terms of TOC, but GAC influent is normally coagulated and filtered water, where TOC = DOC. -
pac_toc()corrections at low DOC and UV254. -
convert_watermg()returnstot_sio4in mg/L as SiO2, matchingdefine_water()input. -
modify_water()now converts TOC, DOC, and BDOC entered in ug/L and DBPs entered in mg/L correctly. Both conversions were inverted. It also acceptstbaaand no longer lists the nonexistentbaaslot. -
modify_water_df()now appliesslot,value, andunitspassed as constants. Before, they were silently ignored and the water was returned unchanged. It now errors when a column it needs is missing.
-
Other changes
-
opensys_ph()widens its CO2 search when more than 100 mg/L of CO2 has to be removed or added, instead of failing with auniroot()error. If no equilibrium dose is found, it gives a clear error. -
solvedose_alk()no longer lists or acceptschemical = "co2", since CO2 doesn’t change alkalinity. It now errors with “Selected chemical addition is not supported” instead of auniroot()error. -
define_water_df()now maps columns todefine_water()arguments by name. - Warnings and errors now use cli. Repeated warnings from
_dffunctions are reported once with the number of rows affected.
tidywater 0.10.0
CRAN release: 2025-08-24
New features
- Revamped helpers
_dfreplacechainandoncefunctions. Usepluck_cols = TRUEto mimiconcebehavior, although it will always return a water column as well. - Virus log removal added to
solvect_chlorinebased on the EPA Guidance Manual Table E-7 (1991) -
modify_watercan now modify multiple water slots at once. Note that in order to modify multiple slots usingmodify_water_df, all input arguments must be included as a list. - Acetic acid added as chemical to
chemdose_ph. In addition to changing pH, dosing acetic acid will also update TOC and DOC of the input water. -
regulate_tocnow available for calculating TOC removal compliance -
gacrun_toc,gac_toc, andgacbv_tocadded to predict TOC removal from GAC treatment using either the EPA WTP model (2001) or the Zachman and Summers (2018) model. Different functions provide different output types: a data frame of the TOC breakthrough curve, a new water with updated TOC, DOC, and UV254 water slots, or the necessary bed volumes to stay below the target effluent TOC. See individual functions for documentation. -
pluck_waterand_dfhelpers sped up by relying on base R instead of purrr -
chemdose_toccan now account for doc removal due to lime softening from the WTP Model (2001). To implement, use thecaoh2argument. - New model
opensys_phadded to predict pH and alkalinity of an input water in an open carbonate system at equilibrium - New function
plot_leadadded to graph the pH vs DIC contour plot for lead solubility - Alkalinity slots added to the water class.
alkandalk_eqrepresent the total alkalinity, and individual alkalinities due to carbonate, phosphate, ammonium, borate, silicate, and hypochlorite have been added as individual slots (eg. carbonate_alk_eq).
Breaking changes
-
_chainand_oncefunctions have been deprecated. Replace with_dffunctions. Code should be similar, but has slightly different outputs. - Default water naming in helper functions has been shortened to remove “_water”. Eg, new default
output_water = "defined", old defaultoutput_water = "defined_water". See function documentation for new defaults. - Total alkalinity (
alk) now accounts for phosphate, silicate, borate, hypochlorite, and ammonia. Could have a minor impact on final pH and alkalinity calculations in waters with those compounds. - Now depends on R >= 4.1.0 for built in pipe operator,
|>
tidywater 0.9.0
CRAN release: 2025-07-03
New features
- New
chemdose_phchemicals: CaOCl2, CaSO4, HNO3, KMnO4, NaF, and Na3PO4 - New model
dissolve_cupredicts the concentration of copper given pH, DIC, and phosphate based on the empirical model described in Lytle et al. (2018).dissolve_cu_oncecan also predict copper for waters in a data frame. -
chemdose_dbpcan now input custom fitting coefficients as a data frame -
chemdose_ph_onceandchemdose_toc_onceare back and only return relevant waters slots in its output. -
decarbonate_ph: function to remove CO2 (H2CO3) from a water and determine the new pH (and division of ions) -
modify_water: function to modify individual slots in a water that handles unit conversions
Breaking changes
-
applied_treatmentslot removed from water. Was not providing any benefit and added complexity. Should be the responsibility of the user to track. -
h2co3slot added towaterclass calculated based on {H} and total carbonate. -
chemdose_phwarns when ion water slots aren’t updated due to NA slots. -
solvedose_phupdated search range to allow for more water qualities without erroring. Updated search process results in slightly different outputs. -
_tocfunctions are DOC-based and previously assumed no particulate TOC removal. In reality, virtually all particulate TOC is removed with other particulates, so models have been updated to return TOC = DOC -
chemdose_toccustom coeff now accepts a data frame instead of a named list - Corrosion index slots removed from
waterclass. -
calculate_corrosionnow outputs a data frame with the corrosion indices as columns.calculate_corrosion_chainremoved because the base function has a numeric output. -
calculate_corrosionupdated CCPP search range to allow for more water qualities without erroring. -
solvect_o3andsolveresid_o3now return zero instead of NaN when the input dose is zero
tidywater 0.8.1
- Pare down examples and vignettes to speed up CRAN checks
- Minor updates to
chemdose_chloraminewarnings.
tidywater 0.8.0
-
calculate_corrosionexpanded CCPP search range (fewer errors)
Breaking changes
- Helper function (
_chainand_once) behavior change: can now specify column name unquoted (eg, alum = AlumDose) - Removed most (
_once) helper functions because the desired output is almost never all water slots as columns. Refer topluck_water(parameter = "all")for same behavior. -
pac_tocnow constrained to accept a smaller range of doses and times. The form of the equation was allowing negative TOC outputs. -
define_water,chemdose_ph,blend_waters, and other pH related functions slightly impacted by a fix in concentration vs activity. Previous code assumed pH = 10^-[H+], code has been corrected to pH = 10^-{H+}
New features
- User may now choose which cation or anion to use for balancing ions
- dic now calculated in
define_water - dic now available in
convert_units -
chemdose_chloramine: chloramine formation model given chlorine, ammonia, time -
chemdose_chlordecaynow has argument,use_chlorine_slot. Function can now use chlorine dose and/or free_chlorine or combined_chlorine slots.
tidywater 0.7.0
CRAN release: 2025-01-22
New features
- chlorine and chloramine decay:
chemdose_chlordecay - New water slots for chloramine chemistry:
combined_chlorine,nh2cl,nhcl2,ncl3 -
solvemass_solidsseparates functionality fromsolvecost_solidsto solve lb/day -
biofilter_toc,chemdose_chlordecay,ozonate_bromate, andsolvecthelpers now available.
Breaking changes
-
chemdose_ctrenamedsolvect_chlorine -
ozonate_ctrenamedsolvect_o3 -
tot_oclslot in water renamedfree_chlorine -
define_waterargument changes:tot_oclchanged tofree_chlorine, addedcombined_chlorine - Helper function (
_chainand_once) behavior change: if multiple values are specified for multiple arguments, all combinations are used.
tidywater 0.6.2
CRAN release: 2024-11-05
- CRAN resubmission.
- Minor changes to DESCRIPTION and examples using
plan
tidywater 0.5.0
Fixes
- default temperature is now 25C
- corrected enthalpy of reaction for ammonium ion
- completed PAC models
New features
- chemdose_ct: CT calculations, including CT actual, CT required, and giardia log removal
- solvecost_ family: cost calculations, including chemicals, power, solids, and labor
- solvemass_ :convert chemical doses from mg/L to lb/day
- solveresid_o3: ozone decay model and corresponding helper function from WTP model
- ozonate_ct: ozone CT model
- validate water function, not exported but useful for function writing
- chemdose_f: fluoride model for alum addition. Requires site specific fitting.
- biofilter_toc: biofiltration model (Terry & Summers)
- added ACH to chemdose_ph
tidywater 0.4.0
New features
- convert_watermg for cleaner water exports
- bromate formation models
- ammonia in pH chemistry
- new water slots for F, Fe, Al, etc
- helper functions for chemdose_dbp
- PAC models (incomplete)
Breaking changes
- treatment slot renamed “applied_treatments”
- solve_ph changes. Should only see different values when po4 is in the water.
- Added hydration to ferric sulfate and renamed coagulants for consistency.
- pluck_water doesn’t allow specification of output_column. It is named by default from the input and parameters. Improved pluck does allow multiple parameters and waters in one function.
tidywater 0.2.0
New features
- TOC removal through coagulation,
chemdose_tocand matching_chainand_oncehelper functions. - DBP formation from coagulation,
chemdose_dbp. No helper functions yet exceptsummarise_dbp - Calculation of corrosion indices,
calculate_corrosionandsummarise_corrosionwith helper functions. - Theoretical lead solubility
dissolve_pbwith helper functions. - Helper function
pluck_waterto pull one slot from awatercolumn in a data frame.
