quadrama / DramaAnalysis

An R package for analysis of dramatic texts
GNU General Public License v3.0
15 stars 2 forks source link

Issue in presence function with actives #157

Closed pagelj closed 4 years ago

pagelj commented 4 years ago

There is a strange error in presence() with line https://github.com/quadrama/DramaAnalysis/blob/master/R/presence.R#L62: conf.active$actives <- rowSums(conf.active[,4:ncol(conf.active)])

Error:

Error in `[.data.frame`(x, , 4:ncol(x), drop = FALSE) : 
  undefined columns selected 
Traceback:
7. stop("undefined columns selected") 
6. `[.data.frame`(x, , 4:ncol(x), drop = FALSE) 
5. x[, 4:ncol(x), drop = FALSE] 
4. as.matrix.data.frame(x[, 4:ncol(x), drop = FALSE], ...) 
3. as.matrix.QDConfiguration(x) 
2. as.matrix(x) 
1. rowSums(conf.active[, 4:ncol(conf.active)])

This occurred for qd:qdjz.0 and qd:x3cv.0, but not for any other text tested (around 40)

Running conf.active[,4:ncol(conf.active)] seems to work fine, the issue is within rowSums

nilsreiter commented 4 years ago

This is a consequence of NA values in the character column.

The second line in this snippet:

drama <- loadDrama("ksd1.0", defaultCollection = "qd")
drama$text <- drama$text[!is.na(drama$text$Speaker.figure_id),]

can be used as hot fix, but we need a better solution.

nilsreiter commented 4 years ago

Added code to loadDrama() that checks whether there are NA values, display warning and remove the rows in the text table.