aiorazabala / qmethod

R package to analyse Q methodology data
GNU General Public License v2.0
34 stars 17 forks source link

qfwe/qzscores accepts matrix as input, but chokes on it #342

Closed maxheld83 closed 8 years ago

maxheld83 commented 8 years ago

as per the docs, qfwe() accepts a matrix for the loa and flagged argument.

However, being thrown matrices, it errors out with:

Error in wraw_all[[n]] : subscript out of bounds

Some digging down in qzscores suggest that the below piece of code is at fault:

while (n <= length(floa)) {
    zsc_sum[,n] <-      rowSums(wraw_all[[n]])
    zsc_mea[,n] <- mean(rowSums(wraw_all[[n]]))
    zsc_std[,n] <-   sd(rowSums(wraw_all[[n]]))
    n <- n+1
  }

The trouble here is that length(floa) only makes sense when floa is a df, not a matrix (wayyy to long in that case).

Changing it to ncol should fix the problem.

maxheld83 commented 8 years ago

turns out this shows up in a number of places, including qfcharact.

maxheld83 commented 8 years ago

I think this might be the kind of bug we could avoid if we were stricter about inputs (either only dataframes, or only matrices) as per #277

maxheld83 commented 8 years ago

@aiorazabala I'm not sure if I got this bug right and/or if it also exists in your master fork, but if so, you might want to hot-fix this .... I think git cherry pick or something should allow you to apply only the above commit.