From a4160409c0a8282d902fb89a6c94ecd2993cc34b Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Thu, 15 Aug 2024 16:35:08 +0200 Subject: [PATCH] fix #88 (#91) --- R/oolong_data_misc.R | 4 ++++ R/oolong_summary_tm.R | 6 +++--- R/oolong_tm.R | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/R/oolong_data_misc.R b/R/oolong_data_misc.R index 7800192..0d7ebc2 100644 --- a/R/oolong_data_misc.R +++ b/R/oolong_data_misc.R @@ -89,3 +89,7 @@ utils::globalVariables(c('cookd', 'diffxy', 'index', 'meanxy', 'word_length', 'a } return(digest::digest(x, algo = "sha1")) } + +.map_dfr <- function(x, f, ...) { + purrr::list_rbind(purrr::map(x, f, ...)) +} diff --git a/R/oolong_summary_tm.R b/R/oolong_summary_tm.R index 22997ed..8f82dcc 100644 --- a/R/oolong_summary_tm.R +++ b/R/oolong_summary_tm.R @@ -66,7 +66,7 @@ res$tlo <- NA res$tlo_p_value <- NA } else { - res$tlo <- .cal_tlo(purrr::map_dfr(all_topic_test_content, ~.), mean_value = FALSE) ### it should not be just the mean. + res$tlo <- .cal_tlo(.map_dfr(all_topic_test_content, ~.), mean_value = FALSE) ### it should not be just the mean. monkey_median <- unlist(replicate(n_iter, .monkey_median(.clone_obj_list(obj_list)))) res$tlo_p_value <- sum(monkey_median > median(res$tlo)) / n_iter } @@ -88,7 +88,7 @@ n_correct <- apply(correction_matrix, 2, sum) res$rater_precision_wsi <- as.vector(n_correct / nrow(correction_matrix)) if (length(obj_list) == 1) { - res$kripp_alpha_wsi <- NA + res$kripp_alpha_wsi <- NA } else { res$kripp_alpha_wsi <- irr::kripp.alpha(t(ifelse(correction_matrix, 2, 1)))$value } @@ -140,5 +140,5 @@ .monkey_median <- function(obj_list) { monkeyed_obj_list <- purrr::map(obj_list, .monkey_test) all_topic_test_content <- purrr::map(monkeyed_obj_list, ~ .$.__enclos_env__$private$test_content$ti) - median(.cal_tlo(purrr::map_dfr(all_topic_test_content, ~.), mean_value = FALSE)) + median(.cal_tlo(.map_dfr(all_topic_test_content, ~.), mean_value = FALSE)) } diff --git a/R/oolong_tm.R b/R/oolong_tm.R index 95ca96e..7fa1121 100644 --- a/R/oolong_tm.R +++ b/R/oolong_tm.R @@ -44,7 +44,7 @@ ## refer to oolong_stm.R for an example .generate_word_intrusion_test <- function(ingredients, bottom_terms_percentile = 0.6, n_top_terms) { - test_items <- purrr::map_dfr(seq_len(ingredients$K), .generate_candidates, terms = ingredients$terms, all_terms = ingredients$all_terms, bottom_terms_percentile = bottom_terms_percentile, n_top_terms = n_top_terms) + test_items <- .map_dfr(seq_len(ingredients$K), .generate_candidates, terms = ingredients$terms, all_terms = ingredients$all_terms, bottom_terms_percentile = bottom_terms_percentile, n_top_terms = n_top_terms) return(test_items) } @@ -90,7 +90,7 @@ target_theta <- ingredients$theta[sample_vec,] k <- ncol(target_theta) target_text <- input_corpus[sample_vec] - test_items <- purrr::map_dfr(seq_len(exact_n), .generate_topic_frame, target_text = target_text, target_theta = target_theta, model_terms = ingredients$model_terms, k = k, n_top_topics = n_top_topics) + test_items <- .map_dfr(seq_len(exact_n), .generate_topic_frame, target_text = target_text, target_theta = target_theta, model_terms = ingredients$model_terms, k = k, n_top_topics = n_top_topics) return(test_items) } @@ -117,7 +117,7 @@ } .generate_wsi <- function(ingredients, n_correct_ws = 3, n_topiclabel_words = 4, wsi_n_top_terms = 20) { - test_content <- purrr::map_dfr(seq_len(ingredients$K), .generate_candidates_wsi, terms = ingredients$terms, n_correct_ws = n_correct_ws, n_topiclabel_words = n_topiclabel_words, wsi_n_top_terms = wsi_n_top_terms) + test_content <- .map_dfr(seq_len(ingredients$K), .generate_candidates_wsi, terms = ingredients$terms, n_correct_ws = n_correct_ws, n_topiclabel_words = n_topiclabel_words, wsi_n_top_terms = wsi_n_top_terms) return(test_content) }