Skip to content

Improve handling of empty dfm #1419

@koheiw

Description

@koheiw

textmodel_* crash when a DFM has no features. We should add a check and raise error like "dfm must have at least one non-zero feature" instead.

(emptydfm <- dfm_trim(data_dfm_lbgexample, 1000))
# Document-feature matrix of: 6 documents, 0 features.
# 6 x 0 sparse Matrix of class "dfm"
#     features
# docs
#   R1
#   R2
#   R3
#   R4
#   R5
#   V1

textmodel_wordscores(emptydfm, c(seq(-1.5, 1.5, .75), NA))
# Error in as(e1, "dgCMatrix")/e2 : <Matrix> / numeric(0) is undefined 

textmodel_wordfish(emptydfm)
#  Error in qatd_cpp_wordfish_dense(as.matrix(x), as.integer(dir), 1/(priors^2),  :   mean(): object has no elements 

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions