Skip to content

Commit

Permalink
Merge pull request #29 from VEuPathDB/fix-21-lonely-bin-list
Browse files Browse the repository at this point in the history
allow BinLists to have only one bin
  • Loading branch information
asizemore authored Oct 3, 2023
2 parents b751b81 + 4f682a1 commit a6ea003
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 44 deletions.
18 changes: 10 additions & 8 deletions R/class-Bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,16 @@ check_bin_range_list <- function(object) {
errors <- c(errors, msg)
}

# no overlapping ranges
sortOrder <- order(binStarts)
binStarts <- binStarts[sortOrder]
binEnds <- binEnds[sortOrder]
binValues <- binValues[sortOrder]
if (any(binStarts[2:length(binStarts)] < binEnds[1:(length(binEnds)-1)], na.rm=TRUE)) {
msg <- "Some provided bins overlap."
errors <- c(errors, msg)
# no overlapping ranges (only useful when multiple bins in the BinList)
if (length(binStarts) > 1) {
sortOrder <- order(binStarts)
binStarts <- binStarts[sortOrder]
binEnds <- binEnds[sortOrder]
binValues <- binValues[sortOrder]
if (any(binStarts[2:length(binStarts)] < binEnds[1:(length(binEnds)-1)], na.rm=TRUE)) {
msg <- "Some provided bins overlap."
errors <- c(errors, msg)
}
}
}

Expand Down
18 changes: 0 additions & 18 deletions man/as.Date-Bin-method.Rd

This file was deleted.

17 changes: 0 additions & 17 deletions man/as.Date-BinList-method.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion man/getVariableSpec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/testthat/test-class-Bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ test_that("BinList validation works", {

# none have start or ends or value and thats ok
expect_equal(length(BinList(S4Vectors::SimpleList(c(bin6, bin7)))), 2)
})

test_that("BinList can handle a list of one", {

bin1 <- Bin(binStart=1, binEnd=2, binLabel='1-2')
lonelyBinList <- BinList(S4Vectors::SimpleList(c(bin1)))
expect_equal(length(lonelyBinList), 1)

})

0 comments on commit a6ea003

Please sign in to comment.