Skip to content

Commit

Permalink
refactor(FV): now get_from_fits validates minimum parameters and allo…
Browse files Browse the repository at this point in the history
…ws to change cumulative names prefix
  • Loading branch information
hdescobarh committed Sep 6, 2024
1 parent 984de8f commit 054e6ed
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions FV_Lab_germination/Code/germination_curves.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,19 @@ plot_by_treatment <- function(fits, treatment) {
#' @param param_names Character vector of curve parameters to keep
#' @param time_interval_names Character vector of names of each time interval
#' @param time_interval Numeric vector of values of time intervals
#' @param cumulative_prefix prefix for name of cumulative percent at each time
#'
get_from_fits <- function(
fits, param_names, time_interval_names, time_intervals) {
fits, param_names = c("a", "b", "c", "y0"), time_interval_names,
time_intervals, cumulative_prefix = "C") {
if (length(time_interval_names) != length(time_intervals)) {
stop("time_interval_names and time_intervals must have the same length")
}

if (!all(c("a", "b", "c", "y0") %in% param_names)) {
stop("param_names must contain a, b, c and y0 parameters")
}

# Get cumulative percent
cumulative_percent <- apply(
fits[, c(time_interval_names, "Total_Seeds")], 1,
Expand All @@ -119,7 +125,10 @@ get_from_fits <- function(
}
)
cumulative_percent <- t(cumulative_percent)
colnames(cumulative_percent) <- paste("C", time_intervals, sep = "")
colnames(cumulative_percent) <- paste(
cumulative_prefix, time_intervals,
sep = ""
)

# Recover from parameters to keep
final_df <- fits[c("Treatment", "Replicate", param_names)]
Expand Down

0 comments on commit 054e6ed

Please sign in to comment.