Skip to content

Instantly share code, notes, and snippets.

@dholstius
Created April 9, 2016 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dholstius/9b6db1c08e9d95925e05333fbe6f1405 to your computer and use it in GitHub Desktop.
Save dholstius/9b6db1c08e9d95925e05333fbe6f1405 to your computer and use it in GitHub Desktop.
Basic insurance against bad args to .Fortran() calls
eval({
ensure_nonnull <- ensures_that(!is.null(.) ~ "Must not be NULL" )
ensure_nonempty <- ensures_that(length(.) > 0 ~ "Must not be empty", +ensure_nonnull )
ensure_finite <- ensures_that(all(is.finite(.)) ~ "Must be finite", +ensure_nonempty )
ensure_positive <- ensures_that(all(. > 0) ~ "Must be positive", +ensure_finite )
ensure_nonnegative <- ensures_that(all(. >= 0) ~ "Must be positive or zero", +ensure_finite )
ensure_unique <- ensures_that(length(unique(.)) == 1)
})
# Wrapped in `eval({...})` b/c otherwise RStudio will complain about syntax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment