Skip to content

kwic does not return data.frame when there are no matches, but should. #242

Description

@conjugateprior

In quanteda 0.9.7-20:

k1 <- kwic(inaugCorpus, "brexit")
class(k1) ## logical
k1 ## NA
k2 <- kwic(inaugCorpus, "independence")
class(k2) ## kwic data.frame

This breaks some natural aggregation procedures, such as

res <- list()
for (i in 1:N)
  res[[ i ]] <- kwic(subcorpus[i], "independence")
do.call(rbind, res) ## stack kwics 

One workaround is to check is.data.frame(k1) before doing anything (not to check is.na(k1) which will trigger warnings when evaluated on a kwic with matches).

As implied by the help page, kwic should return an empty data.frame, not NA.

┆Issue is synchronized with this Asana task

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions