first found in line 3814 (by steve bassett)
fix is to add drop = F so that the matrix is not converted to a vector:
conv_own[,conv_own$Land_Type] <- apply(conv_own[,conv_own$Land_Type,drop=F], 2, function (x) {replace(x, x < 0, 0.00)})
This also happens with extraction in line 3833. The fix here is to check for length:
If conv_col_names has length < 2, and if so treat this replacement as a vector. But you also have to check whether zinds contains an index indicating that this column adds to zero:
if (length(conv_col_names < 2) & length(zinds) > 0) {
conv_own[,conv_col_names][,zinds] = -conv_own2[,conv_col_names][,zinds]
} else {
conv_own[,conv_col_names][,zinds] = -conv_own2[,conv_col_names][,zinds]
}
Note that in the original, it is ok if zinds has length zero because nothing gets changed (i am not sure that it can even have length zero, so maybe it doesn't matter in the new case either, but you don't want to do the replacement if there are no zinds)
first found in line 3814 (by steve bassett) fix is to add drop = F so that the matrix is not converted to a vector: conv_own[,conv_own$Land_Type] <- apply(conv_own[,conv_own$Land_Type,drop=F], 2, function (x) {replace(x, x < 0, 0.00)})
This also happens with extraction in line 3833. The fix here is to check for length:
If conv_col_names has length < 2, and if so treat this replacement as a vector. But you also have to check whether zinds contains an index indicating that this column adds to zero: if (length(conv_col_names < 2) & length(zinds) > 0) { conv_own[,conv_col_names][,zinds] = -conv_own2[,conv_col_names][,zinds] } else { conv_own[,conv_col_names][,zinds] = -conv_own2[,conv_col_names][,zinds] }
Note that in the original, it is ok if zinds has length zero because nothing gets changed (i am not sure that it can even have length zero, so maybe it doesn't matter in the new case either, but you don't want to do the replacement if there are no zinds)