-
Notifications
You must be signed in to change notification settings - Fork 138
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
start check_numbers_decimal #1743
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,6 +190,7 @@ check_number_decimal <- function(x, | |
..., | ||
exit_code = exit_code, | ||
allow_decimal = TRUE, | ||
vector = FALSE, | ||
min = min, | ||
max = max, | ||
allow_na = allow_na, | ||
|
@@ -228,6 +229,7 @@ check_number_whole <- function(x, | |
..., | ||
exit_code = exit_code, | ||
allow_decimal = FALSE, | ||
vector = FALSE, | ||
min = min, | ||
max = max, | ||
allow_na = allow_na, | ||
|
@@ -241,6 +243,7 @@ check_number_whole <- function(x, | |
..., | ||
exit_code, | ||
allow_decimal, | ||
vector, | ||
min, | ||
max, | ||
allow_na, | ||
|
@@ -253,6 +256,10 @@ check_number_whole <- function(x, | |
what <- "a whole number" | ||
} | ||
|
||
if (vector) { | ||
what <- sprintf("%s vector") | ||
} | ||
|
||
if (exit_code == IS_NUMBER_oob) { | ||
min <- min %||% -Inf | ||
max <- max %||% Inf | ||
|
@@ -531,4 +538,43 @@ check_data_frame <- function(x, | |
) | ||
} | ||
|
||
check_numbers_decimal <- function(x, | ||
..., | ||
min = NULL, | ||
max = NULL, | ||
allow_infinite = TRUE, | ||
allow_na = FALSE, | ||
allow_null = FALSE, | ||
arg = caller_arg(x), | ||
call = caller_env()) { | ||
if (missing(x)) { | ||
exit_code <- IS_NUMBER_false | ||
} else if (0 == (exit_code <- max(map_dbl(x, \(x) .standalone_types_check_dot_call( | ||
ffi_standalone_check_number_1.0.7, | ||
x, | ||
allow_decimal = TRUE, | ||
min, | ||
max, | ||
allow_infinite, | ||
allow_na, | ||
allow_null | ||
))))) { | ||
return(invisible(NULL)) | ||
} | ||
|
||
.stop_not_number( | ||
x, | ||
..., | ||
exit_code = exit_code, | ||
allow_decimal = TRUE, | ||
vector = TRUE, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential upgrade: Should probably pass the indices of the failing elements, as well as the reasons, so they can be reported in the error message. These should be truncated if there are too many. But in a first pass it's fine to just fail saying all elements in the vector should follow the required invariants. |
||
min = min, | ||
max = max, | ||
allow_na = allow_na, | ||
allow_null = allow_null, | ||
arg = arg, | ||
call = call | ||
) | ||
} | ||
|
||
# nocov end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,3 +201,13 @@ test_that("`check_data_frame()` checks", { | |
err(checker(list(data.frame(), data.frame()), check_data_frame, allow_null = TRUE)) | ||
}) | ||
}) | ||
|
||
test_that("`check_numbers_decimal` checks", { | ||
expect_null(check_numbers_decimal(c(10, 5.5))) | ||
expect_null(check_numbers_decimal(c(10L, 50L))) | ||
|
||
expect_snapshot({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like you still need to generate and commit this snapshot. |
||
err(checker(, check_numbers_decimal)) | ||
err(checker("10", check_numbers_decimal, allow_na = TRUE, allow_null = TRUE)) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing an argument?