Skip to content

Instantly share code, notes, and snippets.

@dholstius
Last active April 22, 2016 17:13
Show Gist options
  • Save dholstius/bbdae953e6eeefbf80098b8be8ecb9cf to your computer and use it in GitHub Desktop.
Save dholstius/bbdae953e6eeefbf80098b8be8ecb9cf to your computer and use it in GitHub Desktop.
Using the dot (`.`) in `fail_with`
#
# Context:
#
# https://cran.r-project.org/web/packages/ensurer/vignettes/ensurer.html says:
# "It is also possible to use the dot, ., directly in anonymous error handlers defined directly in the call to e.g. ensure_that."
#
# I must be misunderstanding the statement above!
#
library(ensurer)
ensure_only_one <- ensures_that(
length(.) == 1,
fail_with = function (err) paste0("Expecting 1 value but got ", length(.)))
ensure_only_one(LETTERS) # I expect this to yield "got 26" but it yields "got 2" (???)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment