Avoid get() in across_all
This commit is contained in:
@@ -603,14 +603,27 @@ generate_box_plot <- function(plot, config) {
|
|||||||
# Adjust missing values and calculate ranks
|
# Adjust missing values and calculate ranks
|
||||||
adjust_missing_and_rank <- function(df, variables) {
|
adjust_missing_and_rank <- function(df, variables) {
|
||||||
|
|
||||||
# Adjust missing values in Avg_Zscore and Z_lm columns, and apply rank to the specified variables
|
# Loop over each variable
|
||||||
df <- df %>%
|
for (var in variables) {
|
||||||
mutate(across(all_of(variables), list(
|
# Construct column names
|
||||||
Avg_Zscore = ~ if_else(is.na(get(paste0("Avg_Zscore_", cur_column()))), 0.001, get(paste0("Avg_Zscore_", cur_column()))),
|
avg_zscore_col <- paste0("Avg_Zscore_", var)
|
||||||
Z_lm = ~ if_else(is.na(get(paste0("Z_lm_", cur_column()))), 0.001, get(paste0("Z_lm_", cur_column()))),
|
z_lm_col <- paste0("Z_lm_", var)
|
||||||
Rank = ~ rank(get(paste0("Avg_Zscore_", cur_column()))),
|
rank_col <- paste0("Rank_", var)
|
||||||
Rank_lm = ~ rank(get(paste0("Z_lm_", cur_column())))
|
rank_lm_col <- paste0("Rank_lm_", var)
|
||||||
), .names = "{fn}_{col}"))
|
|
||||||
|
# Check if the columns exist in the data frame
|
||||||
|
if (all(c(avg_zscore_col, z_lm_col) %in% names(df))) {
|
||||||
|
# Adjust missing values by replacing NA with 0.001
|
||||||
|
df[[avg_zscore_col]] <- if_else(is.na(df[[avg_zscore_col]]), 0.001, df[[avg_zscore_col]])
|
||||||
|
df[[z_lm_col]] <- if_else(is.na(df[[z_lm_col]]), 0.001, df[[z_lm_col]])
|
||||||
|
|
||||||
|
# Compute ranks and create new columns
|
||||||
|
df[[rank_col]] <- rank(df[[avg_zscore_col]], na.last = "keep")
|
||||||
|
df[[rank_lm_col]] <- rank(df[[z_lm_col]], na.last = "keep")
|
||||||
|
} else {
|
||||||
|
warning(paste("Columns", avg_zscore_col, "or", z_lm_col, "not found in data frame"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return(df)
|
return(df)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user