Skip to content

Commit 33be99b

Browse files
authored
Merge pull request #54 from quanteda/fix-Matrix_1.4.2
Fixes for forthcoming Matrix 1.4.2
2 parents 8971396 + 1cad18c commit 33be99b

File tree

12 files changed

+102
-64
lines changed

12 files changed

+102
-64
lines changed

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.95.1
2+
Version: 0.95.2
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
@@ -42,6 +42,6 @@ Encoding: UTF-8
4242
BugReports: https://github.com/quanteda/quanteda.textstats/issues
4343
LazyData: TRUE
4444
Language: en-GB
45-
RoxygenNote: 7.1.2
45+
RoxygenNote: 7.2.1
4646
SystemRequirements: C++11
4747
Roxygen: list(markdown = TRUE)

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ importFrom(stringi,stri_detect_regex)
8989
importFrom(stringi,stri_length)
9090
importFrom(stringi,stri_split_boundaries)
9191
importFrom(stringi,stri_sub)
92+
importFrom(utils,packageVersion)
9293
useDynLib("quanteda.textstats", .registration = TRUE)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# quanteda.textstats 0.95.2
2+
3+
* Fixes for compatibility with Matrix 1.4.2.
4+
15
# quanteda.textstats 0.95.1
26

37
* Fixed how subsetting (`[`) works for textstat outputs, to fix #50.

R/textstat_entropy.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ textstat_entropy.dfm <- function(x, margin = c("documents", "features"), base =
2727
if (margin == "features")
2828
x <- t(x)
2929
x <- dfm_weight(x, "prop")
30-
x <- as(x, "dgTMatrix")
30+
x <- as(x, "TsparseMatrix")
3131
e <- unlist(lapply(split(x@x, factor(x@i + 1L, levels = seq_len(nrow(x)))),
3232
function(y) sum(y * log(y, base)) * -1), use.names = FALSE)
3333
result <- data.frame(rownames(x), e, stringsAsFactors = FALSE)

R/textstat_frequency.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ textstat_frequency.dfm <- function(x, n = NULL, groups = NULL,
120120

121121
tf <- x
122122
tf <- dfm_group(tf, groups, ...)
123-
tf <- as(tf, "dgTMatrix")
123+
tf <- as(as(tf, "TsparseMatrix"), "dgTMatrix")
124124

125125
df <- dfm_weight(x, "boolean", force = TRUE)
126126
df <- dfm_group(df, groups, ...)
127-
df <- as(df, "dgTMatrix")
127+
df <- as(as(df, "TsparseMatrix"), "dgTMatrix")
128128

129129
result <- data.frame(
130130
feature = colnames(tf)[tf@j + 1L],

R/textstat_readability.R

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,16 @@
391391
#' die Deutsche Sprache. *Zeitschrift für Entwicklungspsychologie und
392392
#' Pädagogische Psychologie* 9(1), 20--28.
393393
#'
394-
#' Danielson, W.A., & Bryan, S.D. (1963). [Computer Automation of Two
394+
#' Danielson, W.A., & Bryan, S.D. (1963). Computer Automation of Two
395395
#' Readability
396-
#' Formulas](https://journals.sagepub.com/doi/abs/10.1177/107769906304000207).
397-
#' *Journalism Quarterly*, 40(2), 201--206.
396+
#' Formulas.
397+
#' *Journalism Quarterly*, 40(2), 201--206. \doi{10.1177/107769906304000207}
398398
#'
399399
#' DuBay, W.H. (2004). [*The Principles of
400-
#' Readability*](http://www.impact-information.com/impactinfo/readability02.pdf).
400+
#' Readability*](https://files.eric.ed.gov/fulltext/ED490073.pdf).
401401
#'
402-
#' Fang, I. E. (1966). [The "Easy listening
403-
#' formula"](https://www.tandfonline.com/doi/abs/10.1080/08838156609363529?journalCode=hbem19).
404-
#' *Journal of Broadcasting & Electronic Media*, 11(1), 63--68.
402+
#' Fang, I. E. (1966). The "Easy listening formula". *Journal of Broadcasting
403+
#' & Electronic Media*, 11(1), 63--68. \doi{10.1080/08838156609363529}
405404
#'
406405
#' Farr, J. N., Jenkins, J.J., & Paterson, D.G. (1951). Simplification of
407406
#' Flesch Reading Ease Formula. *Journal of Applied Psychology*, 35(5): 333.
@@ -416,9 +415,8 @@
416415
#' Gunning, R. (1952). *The Technique of Clear Writing*. New York:
417416
#' McGraw-Hill.
418417
#'
419-
#' Klare, G.R. (1975). Assessing
420-
#' Readability. *Reading Research
421-
#' Quarterly*, 10(1), 62-102. `https://www.jstor.org/stable/747086`
418+
#' Klare, G.R. (1975). Assessing Readability. *Reading Research Quarterly*,
419+
#' 10(1), 62-102. \doi{10.2307/747086}
422420
#'
423421
#' Kincaid, J. P., Fishburne Jr, R.P., Rogers, R.L., & Chissom, B.S. (1975).
424422
#' [Derivation of New Readability Formulas (Automated Readability Index, FOG

R/textstat_simil.R

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,22 @@ textstat_simil.dfm <- function(x, y = NULL, selection = NULL,
315315

316316
if (is.null(min_simil)) {
317317
if (is(temp, "dsTMatrix")) {
318-
temp <- as(temp, "dsyMatrix")
319-
return(new("textstat_simil_symm", as(temp, "dspMatrix"),
318+
retval <- if (packageVersion("Matrix") < "1.4.2") {
319+
as(as(temp, "dsyMatrix"), "dspMatrix") } else {
320+
as(temp, "packedMatrix")
321+
}
322+
retval <- pack(as(temp, "denseMatrix"))
323+
return(new("textstat_simil_symm",
324+
retval,
320325
method = method, margin = margin,
321326
type = "textstat_simil"))
322327
} else {
323-
return(new("textstat_simil", as(temp, "dgeMatrix"),
328+
retval <- if (packageVersion("Matrix") < "1.4.2") {
329+
as(temp, "dgeMatrix") } else {
330+
as(as(temp, "generalMatrix"), "unpackedMatrix")
331+
}
332+
return(new("textstat_simil",
333+
retval,
324334
method = method, margin = margin,
325335
type = "textstat_simil"))
326336
}
@@ -383,6 +393,7 @@ textstat_dist.default <- function(x, y = NULL, selection = NULL,
383393

384394
#' @export
385395
#' @importFrom quanteda featnames is.dfm
396+
#' @importFrom utils packageVersion
386397
textstat_dist.dfm <- function(x, y = NULL, selection = NULL,
387398
margin = c("documents", "features"),
388399
method = c("euclidean",
@@ -431,12 +442,21 @@ textstat_dist.dfm <- function(x, y = NULL, selection = NULL,
431442
p = p, use_na = TRUE)
432443

433444
if (is(temp, "dsTMatrix")) {
434-
temp <- as(temp, "dsyMatrix")
435-
return(new("textstat_dist_symm", as(temp, "dspMatrix"),
445+
retval <- if (packageVersion("Matrix") < "1.4.2") {
446+
as(as(temp, "dsyMatrix"), "dspMatrix") } else {
447+
as(temp, "packedMatrix")
448+
}
449+
return(new("textstat_dist_symm",
450+
retval,
436451
method = method, margin = margin,
437452
type = "textstat_dist"))
438453
} else {
439-
return(new("textstat_dist", as(temp, "dgeMatrix"),
454+
retval <- if (packageVersion("Matrix") < "1.4.2") {
455+
as(temp, "dgeMatrix") } else {
456+
as(as(temp, "generalMatrix"), "unpackedMatrix")
457+
}
458+
return(new("textstat_dist",
459+
retval,
440460
method = method, margin = margin,
441461
type = "textstat_dist"))
442462
}
@@ -546,7 +566,7 @@ diag2na <- function(x) {
546566
i = i, j = j, x = NA,
547567
dims = dim(x), dimnames = dimnames(x)
548568
)
549-
x <- as(x, "dgTMatrix")
569+
x <- as(x, "TsparseMatrix") # as(x, "dgTMatrix")
550570
} else {
551571
stop("x must be a triplet matrix")
552572
}
@@ -555,12 +575,25 @@ diag2na <- function(x) {
555575

556576
proxy2triplet <- function(x, upper) {
557577
if (class(x) %in% c("textstat_dist", "textstat_simil")) {
558-
x <- as(x, "dgTMatrix")
578+
x <- as(x, "TsparseMatrix")
579+
# x <- as(x, "dgTMatrix")
559580
} else {
560-
if (class(x) %in% c("textstat_dist_symm", "textstat_simil_symm"))
561-
x <- as(as(x, "dsyMatrix"), "dsTMatrix")
562-
if (upper)
563-
x <- as(x, "dgTMatrix")
581+
if (class(x) %in% c("textstat_dist_symm", "textstat_simil_symm")) {
582+
# x <- as(x, "dsTMatrix")
583+
x <- if (packageVersion("Matrix") < "1.4.2") {
584+
# as(as(x, "dsyMatrix"), "dsTMatrix")
585+
as(unpack(x), "TsparseMatrix")
586+
} else {
587+
as(unpack(x), "TsparseMatrix")
588+
# as(as(x, "unpackedMatrix"), "TsparseMatrix")
589+
}
590+
}
591+
if (upper) {
592+
x <- if (packageVersion("Matrix") < "1.4.2") {
593+
as(x, "dgTMatrix") } else {
594+
as(as(x, "TsparseMatrix"), "generalMatrix")
595+
}
596+
}
564597
}
565598
return(x)
566599
}
@@ -578,7 +611,14 @@ proxy2triplet <- function(x, upper) {
578611
setMethod("as.matrix", "textstat_simil_sparse",
579612
function(x, omitted = NA, ...) {
580613
x[x == 0] <- omitted
581-
as.matrix(as(x, "dgeMatrix"))
614+
return(
615+
if (packageVersion("Matrix") < "1.4.2") {
616+
as.matrix(as(x, "dgeMatrix"))
617+
} else {
618+
as.matrix(as(x, "unpackedMatrix"))
619+
}
620+
# as.matrix(unpack(as(x, "denseMatrix")))
621+
)
582622
})
583623

584624
#' @export
@@ -587,7 +627,14 @@ setMethod("as.matrix", "textstat_simil_sparse",
587627
setMethod("as.matrix", "textstat_simil_symm_sparse",
588628
function(x, omitted = NA, ...) {
589629
x[x == 0] <- omitted
590-
as.matrix(as(x, "dgeMatrix"))
630+
return(
631+
if (packageVersion("Matrix") < "1.4.2") {
632+
as.matrix(as(x, "dgeMatrix"))
633+
} else {
634+
as.matrix(as(x, "unpackedMatrix"))
635+
}
636+
# as.matrix(unpack(as(x, "denseMatrix")))
637+
)
591638
})
592639

593640
# textstat_proxy ---------

cran-comments.md

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Submission notes
22

33
Purpose:
4-
* To fix errors happening on the checks for 0.94.1 related to empty dfms.
5-
* To implement other minor bug fixes detailed in NEWS.md.
4+
5+
* To ensure compatibility with forthcoming Matrix 1.4.2.
66

77
## Test environments
88

@@ -14,23 +14,7 @@ Purpose:
1414

1515
## R CMD check results
1616

17-
No ERRORs, NOTEs, or WARNINGs, except:
18-
19-
Found the following (possibly) invalid URLs:
20-
URL: https://doi.org/10.1037/h0043254
21-
From: man/textstat_readability.Rd
22-
Status: 400
23-
Message: Bad Request
24-
URL: https://doi.org/10.1037/h0057532
25-
From: man/textstat_readability.Rd
26-
Status: 400
27-
Message: Bad Request
28-
URL: https://doi.org/10.1037/h0076540
29-
From: man/textstat_readability.Rd
30-
Status: 400
31-
Message: Bad Request
32-
33-
These seem to be an issue with CRAN checks, not with the URLs, since I used \doi{} for these. I contacted Uwe Ligges before submitting, and he advised me to ignore these.
17+
No ERRORs, NOTEs, or WARNINGs.
3418

3519
## Downstream dependencies
3620

man/textstat_proxy.Rd

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/textstat_readability.Rd

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)