{{ message }}

# foverlaps throws cryptic error when provided factors#2645

Closed
Tracked in
opened this issue Feb 26, 2018 · 0 comments
Closed
Tracked in

# foverlaps throws cryptic error when provided factors#2645

opened this issue Feb 26, 2018 · 0 comments
Labels

### sritchie73 commented Feb 26, 2018 • edited by arunsrinivasan

 The `foverlaps()` function can only work with interval columns that are numeric (integer, double, integer64). When trying `foverlaps()` with character interval columns you get an error message telling you this: ```# Provided non numeric data, foverlaps throws a sensible error: X <- data.table(id=1, start="a", end="d") Y <- data.table(id=2, start="b", end="e") setkey(X, start, end) setkey(Y, start, end) foverlaps(X , Y)``` ```# 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 factor lf <- factor(letters) X <- data.table(id=1, start=lf, end=lf) Y <- data.table(id=2, start=lf, end=lf) 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, end=nf) Y <- data.table(id=2, start=nf, end=nf) 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 The text was updated successfully, but these errors were encountered:
``` foverlaps provides clearer error message when intervals are factors, c… ```
``` f5b111b ```
`…loses #2645.`