# hardness_prep <- function(x, hardness.string = "Hardness (As CaCO3)", label.string, ...) {
#
# group_var <- rlang::enquos(...)
#
# hardness.df <- x %>%
# dplyr::filter(CHEMICAL_NAME %in% hardness.string) %>%
# dplyr::rename(HARDNESS = RESULT_NUMERIC,
# rlang::sym(paste(, "UNIT")) = RESULT_UNIT,
# HARDNESS_LAB_ANL_METHOD_NAME = LAB_ANL_METHOD_NAME) %>%
# dplyr::select(!!! group_var,
# HARDNESS, HARDNESS_UNIT, HARDNESS_LAB_ANL_METHOD_NAME)
# final.df <- dplyr::left_join(x, hardness.df,
# by = rlang::set_names(sapply(group_var, quo_name)))
# return(final.df)
# }
hardness_correction <- function(x, narrative_col, numeric_col, hardness_col) {
narative_col <- rlang::enquo(narrative_col)
numeric_col <- rlang::enquo(numeric_col)
hardness_col <- rlang::enquo(hardness_col)
ln_represented.vec <- c("exp(0.85 [ln(ppm hardness)] + 0.50)",
"(0.96) exp(0.9422 [ln (ppm hardness)] - 1.7)",
"(0.997) exp (0.846 [ln (hardness)] + 0.0584)",
"{1.46203 - [ln (hardness) (0.145712)] } exp (1.273 [ln (hardness)] - 4.297)",
"(0.998) exp (0.846 [ln (hardness)] + 2.255)",
"0.978 exp(0.8473 [ln(ppm hardness)] + 0.884)")
ln_x.vec <- x %>%
dplyr::filter(grepl("ln", !!narative_col)) %>%
dplyr::pull(!!narative_col) %>%
unique()
ln_not_represented.vec <- ln_x.vec[!ln_x.vec %in% ln_represented.vec]
if (length(ln_not_represented.vec) > 0 ) warning(paste("The following ln equations are found in data frame x but not represented by this function:",
paste(ln_not_represented.vec,
collapse = "', '")))
x %>%
dplyr::mutate(!!numeric_col := dplyr::case_when(
!!narative_col %in% "exp(0.85 [ln(ppm hardness)] + 0.50)" ~ exp(0.85 * log(!!hardness_col) + 0.50),
!!narative_col %in% "(0.96) exp(0.9422 [ln (ppm hardness)] - 1.7)" ~ 0.96 * exp(0.9422 * log(!!hardness_col) - 1.7),
!!narative_col %in% "(0.997) exp (0.846 [ln (hardness)] + 0.0584)" ~ 0.997 * exp(0.846 * log(!!hardness_col) + 0.0584),
!!narative_col %in% "{1.46203 - [ln (hardness) (0.145712)] } exp (1.273 [ln (hardness)] - 4.297)" ~ (1.46203 - log(!!hardness_col) * 0.145712) * (exp(1.273 * log(!!hardness_col) - 4.297)),
!!narative_col %in% "(0.998) exp (0.846 [ln (hardness)] + 2.255)" ~ 0.998 * exp(0.846 * log(!!hardness_col) + 2.255),
!!narative_col %in% "0.978 exp(0.8473 [ln(ppm hardness)] + 0.884)" ~ 0.978 * exp(0.8473 * log(!!hardness_col) + 0.884),
TRUE ~ !!numeric_col))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.