calcChlaAcid <- function(df, pool, ...) {
allColumns <- sum(
grepl(
paste(
c('lab_chla_fluor_1_rep',
'lab_chla_fluor_2_rep',
'chla_acid_std_curve_id'),
collapse = '|'
),
colnames(df)
)
) == 3
if (nrow(df) == 1 & allColumns) {
lab_chla_fluor_1_rep <- df %>% select(starts_with('lab_chla_fluor_1_rep')) %>% pull()
lab_chla_fluor_2_rep <- df %>% select(starts_with('lab_chla_fluor_2_rep')) %>% pull()
stdCurveId <- df %>% pull('chla_acid_std_curve_id')
if (!is.na(stdCurveId) & stdCurveId > 0) {
stdCurve <- getRows(pool, 'standard_curves', id == stdCurveId, columns = c('a', 'b'))
chla_acidified_slope <- stdCurve %>% pull('a')
chla_acidified_intercept <- stdCurve %>% pull('b')
} else {
chla_acidified_slope <- NA
chla_acidified_intercept <- NA
}
if (!any(is.na(c(lab_chla_fluor_1_rep, lab_chla_fluor_2_rep, chla_acidified_slope, chla_acidified_intercept)))) {
return(
(lab_chla_fluor_1_rep - lab_chla_fluor_2_rep) * chla_acidified_slope + chla_acidified_intercept
)
}
}
'KEEP OLD'
}