Gracefully handle empty var cols

This commit is contained in:
2024-09-12 19:24:53 -04:00
parent 88a0429bca
commit 270cc8def5

View File

@@ -171,7 +171,7 @@ calculate_summary_stats <- function(df, variables, group_vars = c("OrfRep", "con
), .names = "{.fn}_{.col}") ), .names = "{.fn}_{.col}")
) )
print(summary_stats) # print(summary_stats)
# Prevent .x and .y suffix issues by renaming columns # Prevent .x and .y suffix issues by renaming columns
df_cleaned <- df %>% df_cleaned <- df %>%
@@ -224,10 +224,10 @@ calculate_interaction_scores <- function(df, max_conc, variables, group_vars = c
across(all_of(variables), list( across(all_of(variables), list(
mean = ~mean(., na.rm = TRUE), mean = ~mean(., na.rm = TRUE),
median = ~median(., na.rm = TRUE), median = ~median(., na.rm = TRUE),
max = ~max(., na.rm = TRUE), max = ~ifelse(all(is.na(.)), NA, max(., na.rm = TRUE)),
min = ~min(., na.rm = TRUE), min = ~ifelse(all(is.na(.)), NA, min(., na.rm = TRUE)),
sd = ~sd(., na.rm = TRUE), sd = ~sd(., na.rm = TRUE),
se = ~sd(., na.rm = TRUE) / sqrt(sum(!is.na(.)) - 1) se = ~ifelse(sum(!is.na(.)) > 1, sd(., na.rm = TRUE) / sqrt(sum(!is.na(.)) - 1), NA)
), .names = "{.fn}_{.col}") ), .names = "{.fn}_{.col}")
) %>% ) %>%
ungroup() ungroup()