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

RXR-567: handle zero-length input in %>=% #28

Merged
merged 3 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(print,nca_output)
export("%<=%")
export(absolute2relative_bsa)
export(accumulation_ratio)
export(add_ruv)
Expand Down
16 changes: 16 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,21 @@ remove_lt_gt <- function(x) {
#' @param x Numeric vector
#' @param y Numeric vector
`%>=%` <- function(x, y) {
if (length(x) == 0 | length(y) == 0) {
return(logical(0))
}
x > y | mapply(function(x, y) isTRUE(all.equal(x, y)), x, y)
}

#' Less-than-or-equal-to with a little room for floating point precision
#' issues
#'
#' @param x Numeric vector
#' @param y Numeric vector
#' @export
`%<=%` <- function(x, y) {
if (length(x) == 0 | length(y) == 0) {
return(logical(0))
}
x < y | mapply(function(x, y) isTRUE(all.equal(x, y)), x, y)
}
18 changes: 18 additions & 0 deletions man/grapes-less-than-equals-grapes.Rd

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

9 changes: 9 additions & 0 deletions tests/testthat/test_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ test_that("%>=% operator works", {
expect_true((0.7 - 0.4) %>=% 0.3)
})

test_that("%<=% operator works", {
expect_true((0.1 + 0.2) %<=% 0.3)
})

test_that("%>=% operator works on vectors", {
res <- c(1, 2, 3, 4) %>=% c(0, 3, 1, 5)
expect_equal(res, c(TRUE, FALSE, TRUE, FALSE))
Expand All @@ -55,3 +59,8 @@ test_that("%>=% operator handles vectors of different lengths", {
expect_equal(2 %>=% c(1, 3), c(TRUE, FALSE))
expect_equal(c(1, 3) %>=% 2, c(FALSE, TRUE))
})

test_that("%>=% handles zero-length input", {
expect_equal(c(1, 3) %>=% numeric(0), logical(0))
expect_equal(numeric(0) %>=% 5, logical(0))
})
jasmineirx marked this conversation as resolved.
Show resolved Hide resolved