Skip to content

Commit 00af203

Browse files
committed
Fix warnings related to forhcoming v3
1 parent 752f58e commit 00af203

25 files changed

+164
-131
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
^LICENSE$
77
^\.github$
88
^CRAN-RELEASE$
9+
^revdep$

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ src/*.o
66
src/*.so
77
src/*.dll
88
quanteda.textstats.Rproj
9+
revdep

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: quanteda.textstats
2-
Version: 0.92.9000
2+
Version: 0.93
33
Title: Textual Statistics for the Quantitative Analysis of Textual Data
44
Description: Textual statistics functions formerly in the 'quanteda' package.
55
Textual statistics for characterizing and comparing textual data. Includes
@@ -17,7 +17,7 @@ Authors@R: c(
1717
)
1818
License: GPL-3
1919
Depends:
20-
R (>= 3.2.0)
20+
R (>= 3.5.0)
2121
Imports:
2222
quanteda,
2323
Matrix,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ importFrom(quanteda,dfm_remove)
6767
importFrom(quanteda,dfm_weight)
6868
importFrom(quanteda,docnames)
6969
importFrom(quanteda,featnames)
70+
importFrom(quanteda,is.corpus)
7071
importFrom(quanteda,is.dfm)
7172
importFrom(quanteda,ndoc)
7273
importFrom(quanteda,nsentence)

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# quanteda.textstats 0.93
22

33
* Minor changes to ensure compatibility with **quanteda** v3.
4+
* Changes to avoid breaking tests on older releases, caused by changes to the default for `stringsAsFactors` in `data.frame()`.
45

56
# quanteda.textstats 0.92
67

R/textstat-methods.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
#' library("quanteda")
3131
#'
3232
#' period <- ifelse(docvars(data_corpus_inaugural, "Year") < 1945, "pre-war", "post-war")
33-
#' dfmat <- dfm(data_corpus_inaugural, groups = period)
33+
#' dfmat <- tokens(data_corpus_inaugural) %>%
34+
#' dfm() %>%
35+
#' dfm_group(groups = period)
3436
#' tstat <- textstat_keyness(dfmat)
3537
#' textstat_select(tstat, 'america*')
3638
#'

R/textstat_frequency.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030
#' @examples
3131
#' library("quanteda")
3232
#' set.seed(20)
33-
#' dfmat1 <- dfm(c("a a b b c d", "a d d d", "a a a"))
33+
#' dfmat1 <- dfm(tokens(c("a a b b c d", "a d d d", "a a a")))
3434
#'
3535
#' textstat_frequency(dfmat1)
3636
#' textstat_frequency(dfmat1, groups = c("one", "two", "one"), ties_method = "first")
3737
#' textstat_frequency(dfmat1, groups = c("one", "two", "one"), ties_method = "average")
3838
#'
3939
#' dfmat2 <- corpus_subset(data_corpus_inaugural, President == "Obama") %>%
40-
#' dfm(remove_punct = TRUE, remove = stopwords("english"))
40+
#' tokens(remove_punct = TRUE) %>%
41+
#' tokens_remove(stopwords("english")) %>%
42+
#' dfm()
4143
#' tstat1 <- textstat_frequency(dfmat2)
4244
#' head(tstat1, 10)
4345
#'

R/textstat_keyness.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,19 @@
5454
#'
5555
#' # compare pre- v. post-war terms using grouping
5656
#' period <- ifelse(docvars(data_corpus_inaugural, "Year") < 1945, "pre-war", "post-war")
57-
#' dfmat1 <- dfm(data_corpus_inaugural, groups = period)
57+
#' dfmat1 <- tokens(data_corpus_inaugural) %>%
58+
#' dfm() %>%
59+
#' dfm_group(groups = period)
5860
#' head(dfmat1) # make sure 'post-war' is in the first row
5961
#' head(tstat1 <- textstat_keyness(dfmat1), 10)
6062
#' tail(tstat1, 10)
6163
#'
6264
#' # compare pre- v. post-war terms using logical vector
63-
#' dfmat2 <- dfm(data_corpus_inaugural)
65+
#' dfmat2 <- dfm(tokens(data_corpus_inaugural))
6466
#' head(textstat_keyness(dfmat2, docvars(data_corpus_inaugural, "Year") >= 1945), 10)
6567
#'
6668
#' # compare Trump 2017 to other post-war preseidents
67-
#' dfmat3 <- dfm(corpus_subset(data_corpus_inaugural, period == "post-war"))
69+
#' dfmat3 <- dfm(tokens(corpus_subset(data_corpus_inaugural, period == "post-war")))
6870
#' head(textstat_keyness(dfmat3, target = "2017-Trump"), 10)
6971
#'
7072
#' # using the likelihood ratio method

R/textstat_lexdiv.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
#' sandwich.")
149149
#' tokens(txt) %>%
150150
#' textstat_lexdiv(measure = c("TTR", "CTTR", "K"))
151-
#' dfm(txt) %>%
151+
#' dfm(tokens(txt)) %>%
152152
#' textstat_lexdiv(measure = c("TTR", "CTTR", "K"))
153153
#'
154154
#' toks <- tokens(corpus_subset(data_corpus_inaugural, Year > 2000))
@@ -382,7 +382,7 @@ compute_lexdiv_dfm_stats <- function(x, measure = NULL, log.base = 10) {
382382
#' @param MSTTR_segment a numeric value defining the size of the each segment
383383
#' for the computation of the the Mean Segmental Type-Token Ratio (Johnson, 1944)
384384
compute_lexdiv_tokens_stats <- function(x, measure = c("MATTR", "MSTTR"),
385-
MATTR_window, MSTTR_segment) {
385+
MATTR_window, MSTTR_segment) {
386386
measure <- match.arg(measure, several.ok = TRUE)
387387
result <- data.frame(document = docnames(x), stringsAsFactors = FALSE)
388388

@@ -426,7 +426,7 @@ compute_mattr <- function(x, MATTR_window = 100L) {
426426
x <- tokens_ngrams(x, n = MATTR_window, concatenator = " ")
427427

428428
# get a list of TTRs by document
429-
temp <- lapply(as.list(x), function(y) textstat_lexdiv(dfm(y), "TTR")[["TTR"]])
429+
temp <- lapply(as.list(x), function(y) textstat_lexdiv(dfm(tokens(y)), "TTR")[["TTR"]])
430430
result <- unlist(lapply(temp, mean))
431431
return(result)
432432
}

R/textstat_readability.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ textstat_readability.corpus <- function(x,
646646
}
647647

648648
if ("Dickes.Steiwer" %in% measure) {
649-
TTR <- textstat_lexdiv(dfm(x, verbose = FALSE), measure = "TTR")$TTR
649+
TTR <- textstat_lexdiv(dfm(tokens(x), verbose = FALSE), measure = "TTR")$TTR
650650
result[["Dickes.Steiwer"]] <- 235.95993 - (73.021 * C / W) - (12.56438 * W / St) - (50.03293 * TTR)
651651
}
652652

0 commit comments

Comments
 (0)