is_prob(1/2) # TRUE
is_prob(2) # FALSE
# vectors:
p_seq <- seq(0, 1, by = .1) # Vector of probabilities
is_prob(p_seq) # TRUE (as scalar, not: TRUE TRUE etc.)
is_prob(c(.1, 2, .9)) # FALSE (as scalar, not: TRUE FALSE etc.)
## watch out for:
# is_prob(NA) # => FALSE + NO warning!
# is_prob(0/0) # => FALSE + NO warning (NA + NaN values)
# is_prob(0/0, NA_warn = TRUE) # => FALSE + warning (NA values)
## ways to fail:
# is_prob(8, NA_warn = TRUE) # => FALSE + warning (outside range element)
# is_prob(c(.5, 8), NA_warn = TRUE) # => FALSE + warning (outside range vector element)
# is_prob("Laplace", NA_warn = TRUE) # => FALSE + warning (non-numeric values)
Run the code above in your browser using DataLab