diff --git a/R/btm.R b/R/btm.R index 41aa8ba..8cbd4c2 100644 --- a/R/btm.R +++ b/R/btm.R @@ -63,9 +63,7 @@ #' @export #' @seealso \code{\link{predict.BTM}}, \code{\link{terms.BTM}}, \code{\link{logLik.BTM}} #' @examples -#' \dontshow{if(require(udpipe)) -#' \{ -#' } +#' \dontshow{if(require(udpipe) & require(data.table))\{} #' library(udpipe) #' data("brussels_reviews_anno", package = "udpipe") #' x <- subset(brussels_reviews_anno, language == "nl") @@ -109,10 +107,7 @@ #' bitermset$n #' sum(biterms$cooc) #' -#' \dontshow{ -#' \} -#' # End of main if statement running only if the required packages are installed -#' } +#' \dontshow{\} # End of main if statement running only if the required packages are installed} #' \dontrun{ #' ## #' ## Visualisation either using the textplot or the LDAvis package @@ -250,6 +245,7 @@ print.BTM <- function(x, ...){ #' one for each topic. #' @export #' @examples +#' \dontshow{if(require(udpipe))\{} #' library(udpipe) #' data("brussels_reviews_anno", package = "udpipe") #' x <- subset(brussels_reviews_anno, language == "nl") @@ -260,6 +256,7 @@ print.BTM <- function(x, ...){ #' scores <- predict(model, newdata = x, type = "sub_w") #' scores <- predict(model, newdata = x, type = "mix") #' head(scores) +#' \dontshow{\} # End of main if statement running only if the required packages are installed} predict.BTM <- function(object, newdata, type = c("sum_b", "sub_w", "mix"), ...){ type <- match.arg(type) stopifnot(inherits(newdata, "data.frame")) @@ -305,6 +302,7 @@ predict.BTM <- function(object, newdata, type = c("sum_b", "sub_w", "mix"), ...) #' @export #' @seealso \code{\link{BTM}}, \code{\link{predict.BTM}}, \code{\link{logLik.BTM}} #' @examples +#' \dontshow{if(require(udpipe))\{} #' library(udpipe) #' data("brussels_reviews_anno", package = "udpipe") #' x <- subset(brussels_reviews_anno, language == "nl") @@ -316,6 +314,7 @@ predict.BTM <- function(object, newdata, type = c("sum_b", "sub_w", "mix"), ...) #' terms(model, threshold = 0.01, top_n = +Inf) #' bi <- terms(model, type = "biterms") #' str(bi) +#' \dontshow{\} # End of main if statement running only if the required packages are installed} terms.BTM <- function(x, type = c("tokens", "biterms"), threshold = 0, top_n = 5, ...){ type <- match.arg(type) if(type %in% "biterms"){ @@ -374,6 +373,7 @@ terms.BTM <- function(x, type = c("tokens", "biterms"), threshold = 0, top_n = 5 #' @export #' @seealso \code{\link{BTM}}, \code{\link{predict.BTM}}, \code{\link{logLik.BTM}} #' @examples +#' \dontshow{if(require(udpipe))\{} #' library(udpipe) #' data("brussels_reviews_anno", package = "udpipe") #' x <- subset(brussels_reviews_anno, language == "nl") @@ -383,6 +383,7 @@ terms.BTM <- function(x, type = c("tokens", "biterms"), threshold = 0, top_n = 5 #' str(biterms) #' tokens <- terms(x, type = "tokens") #' str(tokens) +#' \dontshow{\} # End of main if statement running only if the required packages are installed} terms.data.frame <- function(x, type = c("tokens", "biterms"), window = 15, ...){ type <- match.arg(type) stopifnot(window >= 1) @@ -443,6 +444,7 @@ terms.data.frame <- function(x, type = c("tokens", "biterms"), window = 15, ...) #' } #' @export #' @examples +#' \dontshow{if(require(udpipe))\{} #' library(udpipe) #' data("brussels_reviews_anno", package = "udpipe") #' x <- subset(brussels_reviews_anno, language == "nl") @@ -452,6 +454,7 @@ terms.data.frame <- function(x, type = c("tokens", "biterms"), window = 15, ...) #' model <- BTM(x, k = 5, iter = 5, trace = TRUE, detailed = TRUE) #' fit <- logLik(model) #' fit$ll +#' \dontshow{\} # End of main if statement running only if the required packages are installed} logLik.BTM <- function(object, data = terms.BTM(object, type = 'biterms')$biterms, ...){ stopifnot(inherits(data, "data.frame")) stopifnot(all(c(data[[1]], data[[2]]) %in% rownames(object$phi))) diff --git a/man/BTM.Rd b/man/BTM.Rd index 6e6b0ed..e877d8b 100644 --- a/man/BTM.Rd +++ b/man/BTM.Rd @@ -92,9 +92,7 @@ A biterm is an unorder word pair where \code{'B C' = 'C B'}. Thus, the document These biterms are used to create the model. } \examples{ -\dontshow{if(require(udpipe)) -\{ -} +\dontshow{if(require(udpipe) & require(data.table))\{} library(udpipe) data("brussels_reviews_anno", package = "udpipe") x <- subset(brussels_reviews_anno, language == "nl") @@ -138,10 +136,7 @@ head(bitermset$biterms, 100) bitermset$n sum(biterms$cooc) -\dontshow{ -\} -# End of main if statement running only if the required packages are installed -} +\dontshow{\} # End of main if statement running only if the required packages are installed} \dontrun{ ## ## Visualisation either using the textplot or the LDAvis package diff --git a/man/logLik.BTM.Rd b/man/logLik.BTM.Rd index 676544a..07e4685 100644 --- a/man/logLik.BTM.Rd +++ b/man/logLik.BTM.Rd @@ -26,6 +26,7 @@ of the biterms alongside the BTM model. Calculated as \code{sum(phi[term1, ] * p Get the likelihood how good biterms are fit by the BTM model } \examples{ +\dontshow{if(require(udpipe))\{} library(udpipe) data("brussels_reviews_anno", package = "udpipe") x <- subset(brussels_reviews_anno, language == "nl") @@ -35,6 +36,7 @@ x <- x[, c("doc_id", "lemma")] model <- BTM(x, k = 5, iter = 5, trace = TRUE, detailed = TRUE) fit <- logLik(model) fit$ll +\dontshow{\} # End of main if statement running only if the required packages are installed} } \seealso{ \code{\link{BTM}}, \code{\link{predict.BTM}}, \code{\link{terms.BTM}} diff --git a/man/predict.BTM.Rd b/man/predict.BTM.Rd index f825550..810de6f 100644 --- a/man/predict.BTM.Rd +++ b/man/predict.BTM.Rd @@ -34,6 +34,7 @@ To infer the topics in a document, it is assumed that the topic proportions of a is driven by the expectation of the topic proportions of biterms generated from the document. } \examples{ +\dontshow{if(require(udpipe))\{} library(udpipe) data("brussels_reviews_anno", package = "udpipe") x <- subset(brussels_reviews_anno, language == "nl") @@ -44,6 +45,7 @@ scores <- predict(model, newdata = x, type = "sum_b") scores <- predict(model, newdata = x, type = "sub_w") scores <- predict(model, newdata = x, type = "mix") head(scores) +\dontshow{\} # End of main if statement running only if the required packages are installed} } \references{ Xiaohui Yan, Jiafeng Guo, Yanyan Lan, Xueqi Cheng. A Biterm Topic Model For Short Text. WWW2013, diff --git a/man/terms.BTM.Rd b/man/terms.BTM.Rd index 39e2722..3b1f9ad 100644 --- a/man/terms.BTM.Rd +++ b/man/terms.BTM.Rd @@ -36,6 +36,7 @@ Note that a biterm is unordered, in the output of \code{type='biterms'} term1 is Get highest token probabilities for each topic or get biterms used in the model } \examples{ +\dontshow{if(require(udpipe))\{} library(udpipe) data("brussels_reviews_anno", package = "udpipe") x <- subset(brussels_reviews_anno, language == "nl") @@ -47,6 +48,7 @@ terms(model, top_n = 10) terms(model, threshold = 0.01, top_n = +Inf) bi <- terms(model, type = "biterms") str(bi) +\dontshow{\} # End of main if statement running only if the required packages are installed} } \seealso{ \code{\link{BTM}}, \code{\link{predict.BTM}}, \code{\link{logLik.BTM}} diff --git a/man/terms.data.frame.Rd b/man/terms.data.frame.Rd index b058144..864d84f 100644 --- a/man/terms.data.frame.Rd +++ b/man/terms.data.frame.Rd @@ -43,6 +43,7 @@ This extracts words occurring in the neighbourhood of one another, within a cert The default setting provides the biterms used when fitting \code{\link{BTM}} with the default window parameter. } \examples{ +\dontshow{if(require(udpipe))\{} library(udpipe) data("brussels_reviews_anno", package = "udpipe") x <- subset(brussels_reviews_anno, language == "nl") @@ -52,6 +53,7 @@ biterms <- terms(x, window = 15, type = "biterms") str(biterms) tokens <- terms(x, type = "tokens") str(tokens) +\dontshow{\} # End of main if statement running only if the required packages are installed} } \seealso{ \code{\link{BTM}}, \code{\link{predict.BTM}}, \code{\link{logLik.BTM}}