diff --git a/instat/static/InstatObject/R/Backend_Components/calculations.R b/instat/static/InstatObject/R/Backend_Components/calculations.R index 2f3191c214..6f1b349524 100644 --- a/instat/static/InstatObject/R/Backend_Components/calculations.R +++ b/instat/static/InstatObject/R/Backend_Components/calculations.R @@ -494,7 +494,7 @@ DataBook$set("public", "apply_instat_calculation", function(calc, curr_data_list # if it is a ordered factor... if (any(stringr::str_detect("ordered", col_data_type))){ # put in here the ones that DO work for ordered factor - if (any(grepl("summary_count_non_missing|summary_count_missing|summary_count|summary_min|summary_max|summary_range|summary_median|summary_quantile|p10|p20|p25|p30|p33|p40|p60|p67|p70|p75|p80|p90", formula_fn_exp))){ + if (any(grepl("summary_count_non_missing|summary_count_missing|summary_n_distinct|summary_count|summary_min|summary_max|summary_range|summary_median|summary_quantile|p10|p20|p25|p30|p33|p40|p60|p67|p70|p75|p80|p90", formula_fn_exp))){ curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% dplyr::summarise(!!calc$result_name := !!rlang::parse_expr(calc$function_exp)) } else { @@ -505,7 +505,7 @@ DataBook$set("public", "apply_instat_calculation", function(calc, curr_data_list # if it is a factor or character, do not work for anything except... } else if (any(stringr::str_detect("factor | character", col_data_type))){ # put in here the ones that DO work for factor or character - if (any(grepl("summary_count_non_missing|summary_count_missing|summary_count", formula_fn_exp))){ + if (any(grepl("summary_count_non_missing|summary_count_missing|summary_n_distinct|summary_count", formula_fn_exp))){ curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% dplyr::summarise(!!calc$result_name := !!rlang::parse_expr(calc$function_exp)) } else { @@ -846,4 +846,4 @@ find_df_from_calc_from <- function(x, column) { if(column %in% x[[i]]) return(names(x)[i]) } return("") -} \ No newline at end of file +} diff --git a/instat/static/InstatObject/R/Backend_Components/summary_functions.R b/instat/static/InstatObject/R/Backend_Components/summary_functions.R index 397a72b261..4371ef7556 100644 --- a/instat/static/InstatObject/R/Backend_Components/summary_functions.R +++ b/instat/static/InstatObject/R/Backend_Components/summary_functions.R @@ -1113,7 +1113,7 @@ summary_nth <- function(x, nth_value, order_by = NULL, ...) { # n_distinct function summary_n_distinct<- function(x, na.rm = FALSE, ...) { - return(dplyr::n_distinct(x = x, na.rm = na.rm)) + return(dplyr::n_distinct(x, na.rm = na.rm)) } # sample function