blend_waters | R Documentation |
This function takes a vector of waters defined by define_water
and a vector of ratios and outputs a new water object with updated ions and pH.
For a single blend use blend_waters
; for a dataframe use blend_waters_chain
.
Use pluck_water to get values from the output water as new dataframe columns.
blend_waters(waters, ratios)
blend_waters_chain(df, waters, ratios, output_water = "blended_water")
waters |
Vector of source waters created by define_water. For |
ratios |
Vector of ratios in the same order as waters. (Blend ratios must sum to 1). For |
df |
a data frame containing a water class column, which has already been computed using define_water_chain |
output_water |
name of output column storing updated parameters with the class, water. Default is "blended_water". |
For large datasets, using fn_once
or fn_chain
may take many minutes to run. These types of functions use the furrr package
for the option to use parallel processing and speed things up. To initialize parallel processing, use
plan(multisession)
or plan(multicore)
(depending on your operating system) prior to your piped code with the
fn_once
or fn_chain
functions. Note, parallel processing is best used when your code block takes more than a minute to run,
shorter run times will not benefit from parallel processing.#'
blend_waters
returns a water class object with blended water quality parameters.
blend_waters_chain
returns a data frame with a water class column containing blended water quality
define_water
water1 <- define_water(7, 20, 50)
water2 <- define_water(7.5, 20, 100, tot_nh3 = 2)
blend_waters(c(water1, water2), c(.4, .6))
library(dplyr)
example_df <- water_df %>%
slice_head(n = 3) %>%
define_water_chain() %>%
chemdose_ph_chain(naoh = 22) %>%
mutate(
ratios1 = .4,
ratios2 = .6
) %>%
blend_waters_chain(
waters = c("defined_water", "dosed_chem_water"),
ratios = c("ratios1", "ratios2"), output_water = "Blending_after_chemicals"
)
waterA <- define_water(7, 20, 100, tds = 100)
example_df <- water_df %>%
slice_head(n = 3) %>%
define_water_chain() %>%
blend_waters_chain(waters = c("defined_water", waterA), ratios = c(.8, .2))
# Initialize parallel processing
library(furrr)
# plan(multisession)
example_df <- water_df %>%
define_water_chain() %>%
balance_ions_chain() %>%
chemdose_ph_chain(naoh = 22, output_water = "dosed") %>%
blend_waters_chain(waters = c("defined_water", "dosed", "balanced_water"), ratios = c(.2, .3, .5))
# Optional: explicitly close multisession processing
# plan(sequential)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.