diff --git a/DESCRIPTION b/DESCRIPTION index 6dc0da45f..31d4752c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: stm Type: Package Title: Estimation of the Structural Topic Model Version: 1.2.1 -Date: 2017-03-01 +Date: 2017-03-03 Author: Margaret Roberts [aut, cre], Brandon Stewart [aut, cre], Dustin Tingley [aut, cre], diff --git a/R/stm-package.R b/R/stm-package.R index 9f7cfbbf4..2963a8e9f 100644 --- a/R/stm-package.R +++ b/R/stm-package.R @@ -65,11 +65,11 @@ NULL #' @docType data #' @format A data frame with 351 observations on the following 3 variables. #' \describe{ -#' \item{\code{MetaID"}}{A numeric vector containing identification +#' \item{\code{MetaID}}{A numeric vector containing identification #' numbers; not used for analysis} #' \item{\code{treatment}}{A numeric vector #' indicating treatment condition} -#' \item{\code{pid_rep"}}{A numeric vector of +#' \item{\code{pid_rep}}{A numeric vector of #' party identification} #' \item{\code{open.ended.response}}{A character vector #' of the subject's open ended response} diff --git a/R/stm.R b/R/stm.R index 684854d65..96d6ef700 100644 --- a/R/stm.R +++ b/R/stm.R @@ -340,11 +340,14 @@ #' prevalence=~treatment + s(pid_rep), data=out$meta) #' #' #The same example using quanteda instead of tm via textProcessor() +#' #Note this example works with quanteda version 0.9.9-31 and later #' require(quanteda) #' gadarian_corpus <- corpus(gadarian, text_field = "open.ended.response") #' gadarian_dfm <- dfm(gadarian_corpus, #' remove = stopwords("english"), #' stem = TRUE) +#' stm_from_dfm <- stm(gadarian_dfm, K = 3, prevalence = ~treatment + s(pid_rep), +#' data = docvars(gadarian_corpus)) #' #' #An example of restarting a model #' mod.out <- stm(out$documents, out$vocab, 3, prevalence=~treatment + s(pid_rep), diff --git a/man/gadarian.Rd b/man/gadarian.Rd index c73f00126..7a5281395 100644 --- a/man/gadarian.Rd +++ b/man/gadarian.Rd @@ -7,11 +7,11 @@ \title{Gadarian and Albertson data} \format{A data frame with 351 observations on the following 3 variables. \describe{ -\item{\code{MetaID"}}{A numeric vector containing identification +\item{\code{MetaID}}{A numeric vector containing identification numbers; not used for analysis} \item{\code{treatment}}{A numeric vector indicating treatment condition} -\item{\code{pid_rep"}}{A numeric vector of +\item{\code{pid_rep}}{A numeric vector of party identification} \item{\code{open.ended.response}}{A character vector of the subject's open ended response} diff --git a/man/stm.Rd b/man/stm.Rd index 58a815bc4..af6004841 100644 --- a/man/stm.Rd +++ b/man/stm.Rd @@ -352,11 +352,14 @@ mod.out <- stm(out$documents, out$vocab, 3, prevalence=~treatment + s(pid_rep), data=out$meta) #The same example using quanteda instead of tm via textProcessor() +#Note this example works with quanteda version 0.9.9-31 and later require(quanteda) gadarian_corpus <- corpus(gadarian, text_field = "open.ended.response") gadarian_dfm <- dfm(gadarian_corpus, remove = stopwords("english"), stem = TRUE) +stm_from_dfm <- stm(gadarian_dfm, K = 3, prevalence = ~treatment + s(pid_rep), + data = docvars(gadarian_corpus)) #An example of restarting a model mod.out <- stm(out$documents, out$vocab, 3, prevalence=~treatment + s(pid_rep), diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf new file mode 100644 index 000000000..05f869148 Binary files /dev/null and b/tests/testthat/Rplots.pdf differ diff --git a/tests/testthat/test-quanteda-stm.R b/tests/testthat/test-quanteda-stm.R index 7864d7466..01d4a20df 100644 --- a/tests/testthat/test-quanteda-stm.R +++ b/tests/testthat/test-quanteda-stm.R @@ -4,17 +4,22 @@ require(quanteda) test_that("Test that stm works on a quanteda dfm", { require(quanteda) - gadarian_corpus <- corpus(gadarian, text_field = "open.ended.response") - gadarian_dfm <- dfm(gadarian_corpus, - remove = stopwords("english"), - stem = TRUE) - set.seed(10012) # NYU :-) - stm_from_dfm <- stm(gadarian_dfm, - K = 3, - prevalence = ~treatment + s(pid_rep), - data = docvars(gadarian_corpus), - max.em.its=2) - expect_identical(class(stm_from_dfm), "STM") + if(utils::compareVersion(as.character(utils::packageVersion("quanteda")), "0.9.9-31") >= 0) { + gadarian_corpus <- corpus(gadarian, text_field = "open.ended.response") + gadarian_dfm <- dfm(gadarian_corpus, + remove = stopwords("english"), + stem = TRUE) + set.seed(10012) # NYU :-) + stm_from_dfm <- stm(gadarian_dfm, + K = 3, + prevalence = ~treatment + s(pid_rep), + data = docvars(gadarian_corpus), + max.em.its=2) + expect_identical(class(stm_from_dfm), "STM") + } else { + #basically if the version is old, just skip this test for now. + expect_identical("STM", "STM") + } }) test_that("Test that stm works on a classic stm object structure", {