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

Have check_package() return error or TRUE (on valid) #245

Closed
peterdesmet opened this issue Jul 14, 2023 · 6 comments · Fixed by #247
Closed

Have check_package() return error or TRUE (on valid) #245

peterdesmet opened this issue Jul 14, 2023 · 6 comments · Fixed by #247
Assignees
Milestone

Comments

@peterdesmet
Copy link
Member

Suggested in camtraptor July 2023 coding sprint

check_package() currently returns the object itself, so it can be used in pipes, but this reads oddly. Rather, check_package() should return TRUE, exactly how frictionless:::check_package() works.

This change will effect the use in other functions. There it should be used as:

check_package(package)
# next steps

Not:

check_package(package) %>% next steps
@peterdesmet peterdesmet added this to the v0.20 milestone Jul 14, 2023
@PietrH
Copy link
Member

PietrH commented Jul 14, 2023

Do we also want to move check_package() outside of zzz.R?

@peterdesmet
Copy link
Member Author

Yes

@damianooldoni
Copy link
Member

Thanks @PietrH to work on this! 👍
I will handle this PR after merging #223.

@damianooldoni
Copy link
Member

Actually frictionless:::check_package() doesn't return TRUE, but nothing. And actually it 's what I expected by our function as well. I am working on this in #247

@PietrH
Copy link
Member

PietrH commented Jul 25, 2023

I think they should probably return something invisibly, similar to testthat, there is a vignette on custom expectations: https://testthat.r-lib.org/articles/custom-expectation.html?q=expect#expectation-basics

I chose TRUE because this is the behaviour of assertthat, assertions either return an error, or TRUE if all is good. This way they can be used in internal logic.

On this note, we could use the on_failure() helper from assertthat, this is an example from their documentation;

is_odd <- function(x) {
  assert_that(is.numeric(x), length(x) == 1)
  x %% 2 == 1
}
assert_that(is_odd(2))
# Error: is_odd(x = 2) is not TRUE

on_failure(is_odd) <- function(call, env) {
  paste0(deparse(call$x), " is even")
}
assert_that(is_odd(2))
# Error: 2 is even

testthat seems to mostly return the expectation, so expect_length() will return the length when passing, and a message/error if not.


So, do we want check_package() to behave more like assertthat or more like testthat?

@damianooldoni
Copy link
Member

Hi @PietrH. Behavior of assertthat seems to me ok. I was actually wrong in my previous comment. Or, let's say, not completely correct.

The difference between our function and the frictionless::check_package() was in the last if statement containing an assertion.

Without the final return(TRUE) you wrote, the output of the function was different depending on the evaluation of the if condition. If the condition was not satisfied the function would return nothing, while if the condition was satisfied than the output was TRUE or FALSE depending on the output of the assertion in the if.

So, I added back the return(TRUE) you wrote. Well done!

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 a pull request may close this issue.

3 participants