Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow BinLists to have only one bin #29

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

})
Loading