You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
foverlaps throws cryptic error when provided factors #2645
# Error in foverlaps(X, Y) : # The last two columns in by.x should correspond to the 'start' and 'end' intervals # in data.table 'x' and must be integer/numeric type.
When trying with a factor, you get a cryptic error message:
# The same, but coded as a factorlf<-factor(letters)
X<- data.table(id=1, start=lf[1], end=lf[4])
Y<- data.table(id=2, start=lf[2], end=lf[5])
setkey(X, start, end)
setkey(Y, start, end)
foverlaps(X, Y)
# Error in if (any(x[[xintervals[2L]]] - x[[xintervals[1L]]] < 0L)) stop("All entries # in column ", : # missing value where TRUE/FALSE needed# In addition: Warning message:# In Ops.factor(x[[xintervals[2L]]], x[[xintervals[1L]]]) :# ‘-’ not meaningful for factors
The same is true if (for whatever reason) you have numeric interval columns coded as factors:
# Numeric factors also have this problem:nf<-factor(sort(rnorm(10)))
X<- data.table(id=1, start=nf[1], end=nf[4])
Y<- data.table(id=2, start=nf[2], end=nf[5])
setkey(X, start, end)
setkey(Y, start, end)
foverlaps(X, Y)
# Error in if (any(x[[xintervals[2L]]] - x[[xintervals[1L]]] < 0L)) stop("All entries # in column ", : # missing value where TRUE/FALSE needed# In addition: Warning message:# In Ops.factor(x[[xintervals[2L]]], x[[xintervals[1L]]]) :# ‘-’ not meaningful for factors
In these cases, the foverlaps() function should throw the first error message stating that it cannot work with factors
Activity