ensurer
ensurer copied to clipboard
Added error-handling for piping
Changed default behavior of error handling in two ways:
- fail_with default is now try(stop(e))
- if class(.value) == ‚try-error‘ return .value immediately
Problem is that ensure
would no longer "ensure" by default:
get_important_message %>% # suppose this fails, maybe the result is say, `FALSE`
ensure_that(is.character) %>%
send_message
Since try-error
s actually pass is.character
you could end up sending the error in this example.
Even though this is a pseudo-example it shows that ensure
did not ensure that get_important_message
got a character message before allowing control to be handed over to send_message
, which may send an error rather than the message.
Also, in your example, why not just have both conditions in one call to ensure
rather than chaining them. The latter option is really meant to be used when you don't want to check this before knowing that the previous call passed.