R/makeConcFunc.R

Defines functions makeConcFunc

makeConcFunc <- function(dat) {
  
  if(is.data.frame(dat)){
  
  funcs <- list()  # Initialize an empty list to store the functions
    
  names(dat) <- gsub(pattern = "conc_fresh.", replacement = "", x = names(dat))
  names <- names(dat[,!grepl("time", names(dat))])
  tconc_fresh <- t(dat[, names])
  ttime <- t(dat)["time", ]
  
  for (i in 1:(length(dat) - 1)) {
    fun_name <- paste0('conc_fresh_fun_', names[i])
    fun <- approxfun(ttime, tconc_fresh[i, ], method = 'constant', f = 0,
                     yleft = tconc_fresh[i, 1], yright = tconc_fresh[i, ncol(tconc_fresh)], rule = 2)
    
    # Assign the function to the list using the function name as a list element name
    funcs[[fun_name]] <- fun
  }
  } else{
  
  funcs <- dat
  
  }
  
  return(funcs)  # Return the list of functions
}
sashahafner/ATM99 documentation built on June 14, 2025, 5:34 p.m.