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

Improve error message for assertions of length 0 #22

Merged
merged 2 commits into from
Mar 30, 2015
Merged

Improve error message for assertions of length 0 #22

merged 2 commits into from
Mar 30, 2015

Conversation

paulstaab
Copy link
Contributor

This improves the error message when the assertion evaluates to a vector of length 0. Currently, assertthat throws

assert_that(logical())
# Error in if (!res) { : argument is of length zero

@@ -87,6 +87,8 @@ check_result <- function(x) {
stop("assert_that: assertion must return a logical value", call. = FALSE)
if (any(is.na(x)))
stop("assert_that: missing values present in assertion", call. = FALSE)
if (length(x) == 0)
stop("assert_that: assertion has length 0", call. = FALSE)
if (length(x) > 1) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just making this length(x) != 1 and updating the message accordingly

@paulstaab
Copy link
Contributor Author

Done. Do you want we to squash the commits?

hadley added a commit that referenced this pull request Mar 30, 2015
Improve error message for assertions of length 0
@hadley hadley merged commit e183ccd into hadley:master Mar 30, 2015
@hadley
Copy link
Owner

hadley commented Mar 30, 2015

I don't care too much about a clean history for simple stuff like this. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants