{{ 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
Assignees
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[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 The text was updated successfully, but these errors were encountered:
mentioned this issue Feb 26, 2018
self-assigned this Mar 19, 2018
mentioned this issue Aug 20, 2018
closed this as completed in ``` Rdatatable/data.table@c4b195f ``` Feb 16, 2019
pushed a commit that referenced this issue Apr 3, 2019
``` foverlaps provides clearer error message when intervals are factors, c… ```
``` f5b111b ```
`…loses #2645.`