From 6c0b9ce0db8b447e4f1425dda871dcf2bb8332cb Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Mon, 17 May 2021 21:20:35 +0200 Subject: [PATCH] fix a bug of ti when input_corpus is NULL, ref #49 --- R/oolong_tm.R | 3 +++ README.html | 2 +- overview_gh.Rmd | 2 +- overview_gh.md | 6 ++++-- tests/testthat/test-ui.R | 5 ++++- vig_body.Rmd | 2 +- vignettes/overview.Rmd | 2 +- 7 files changed, 15 insertions(+), 7 deletions(-) diff --git a/R/oolong_tm.R b/R/oolong_tm.R index f832f5a..d1e0a29 100644 --- a/R/oolong_tm.R +++ b/R/oolong_tm.R @@ -249,6 +249,9 @@ .generate_test_content <- function(input_model, input_corpus = NULL, n_top_terms = 5, bottom_terms_percentile = 0.6, exact_n = NULL, frac = 0.01, n_top_topics = 3, n_topiclabel_words = 8, difficulty = 1, use_frex_words = FALSE, input_dfm = NULL, btm_dataframe = NULL, type = "witi", n_correct_ws = 3, wsi_n_top_terms = 20) { ingredients <- .extract_ingredients(.convert_input_model_s3(input_model), n_top_terms = n_top_terms, difficulty = difficulty, need_topic = !is.null(input_corpus), n_topiclabel_words = n_topiclabel_words, input_dfm = input_dfm, use_frex_words = use_frex_words, input_corpus = input_corpus, btm_dataframe = btm_dataframe) + if (type %in% c("ti") & is.null(ingredients$theta)) { + .cstop(TRUE, "input_corpus can't be NULL for generating oolong test object with only topic intrusion test.") + } test_content <- list() if (type %in% c("wi", "witi")) { test_content$word <- .generate_word_intrusion_test(ingredients, bottom_terms_percentile = bottom_terms_percentile, n_top_terms = n_top_terms) diff --git a/README.html b/README.html index c2f2af9..ed3ee9a 100644 --- a/README.html +++ b/README.html @@ -605,7 +605,7 @@

oolong

-

Travis build status Codecov test coverage joss stataus zenodo CRAN status R-CMD-check

+

Travis build status Codecov test coverage joss stataus zenodo CRAN status R-CMD-check

diff --git a/overview_gh.Rmd b/overview_gh.Rmd index e3b11a7..2c01851 100644 --- a/overview_gh.Rmd +++ b/overview_gh.Rmd @@ -236,7 +236,7 @@ All the API endpoints are the same, except the one for the creation of topic int ```{r warplda2} ### Just word intrusion test. -oolong_test <- ti(abstracts_warplda, userid = "Lionel") +oolong_test <- wi(abstracts_warplda, userid = "Lionel") oolong_test ``` diff --git a/overview_gh.md b/overview_gh.md index 91b832d..6d74ec0 100644 --- a/overview_gh.md +++ b/overview_gh.md @@ -373,15 +373,17 @@ topic intrusion test cases. You must supply also the `input_dfm`. ``` r ### Just word intrusion test. -oolong_test <- ti(abstracts_warplda, userid = "Lionel") +oolong_test <- wi(abstracts_warplda, userid = "Lionel") oolong_test #> #> ── oolong (topic model) ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── -#> ✖ WI ✖ TI ✖ WSI +#> ✔ WI ✖ TI ✖ WSI #> ☺ Lionel +#> ℹ WI: k = 20, 0 coded. #> #> ── Methods ── #> +#> • <$do_word_intrusion_test()>: do word intrusion test #> • <$lock()>: finalize and see the results ``` diff --git a/tests/testthat/test-ui.R b/tests/testthat/test-ui.R index 54a1c65..39f0fd8 100644 --- a/tests/testthat/test-ui.R +++ b/tests/testthat/test-ui.R @@ -33,7 +33,10 @@ test_that("wi basic", { test_that("witi basic", { skip_on_cran() - expect_error(witi(abstracts_stm, abstracts$text), NA) + expect_error(witi(abstracts_stm, abstracts$text), NA) + ## We need to talk about how to handle these two. + expect_error(witi(abstracts_stm), NA) + expect_error(witi(abstracts_warplda), NA) expect_error(witi(abstracts_warplda, abstracts$text)) expect_error(witi(abstracts_warplda, abstracts$text, input_dfm = abstracts_dfm), NA) expect_error(witi(abstracts_btm, abstracts$text)) diff --git a/vig_body.Rmd b/vig_body.Rmd index 0355f2c..7b35cd6 100644 --- a/vig_body.Rmd +++ b/vig_body.Rmd @@ -220,7 +220,7 @@ All the API endpoints are the same, except the one for the creation of topic int ```{r warplda2} ### Just word intrusion test. -oolong_test <- ti(abstracts_warplda, userid = "Lionel") +oolong_test <- wi(abstracts_warplda, userid = "Lionel") oolong_test ``` diff --git a/vignettes/overview.Rmd b/vignettes/overview.Rmd index df1a4d4..1a79aa2 100644 --- a/vignettes/overview.Rmd +++ b/vignettes/overview.Rmd @@ -239,7 +239,7 @@ All the API endpoints are the same, except the one for the creation of topic int ```{r warplda2} ### Just word intrusion test. -oolong_test <- ti(abstracts_warplda, userid = "Lionel") +oolong_test <- wi(abstracts_warplda, userid = "Lionel") oolong_test ```