COMPASS-DOE / PoolDilutionR

Home of PoolDilutionR, a package for easily calculating gross rates from isotope pool dilution data
Other
3 stars 0 forks source link

Smallish things to consider (spit and polish) #22

Closed bpbond closed 1 year ago

bpbond commented 1 year ago
bpbond commented 1 year ago

Re the last point, here's a brief example:

# A small helper function that calls the optimizer and records ID
fit_func <- function(dat) {
  out <- pdr_optimize_tidy(time = dat$time_days, 
                           m = dat$cal12CH4ml + dat$cal13CH4ml,
                           n = dat$cal13CH4ml, 
                           m_prec = 0.001, 
                           ap_prec = 1, 
                           P = 0.5,
                           quiet = TRUE)
  out$id <- dat$id[1]
  out
}

# Split the data by ID...
morris_split <- split(Morris2023, Morris2023$id)
# ...apply the function to each grouping of data...
fits <- lapply(morris_split, FUN = fit_func)
# ...and recombine
do.call(rbind, fits)