-
Notifications
You must be signed in to change notification settings - Fork 1
/
prob.R
56 lines (50 loc) · 1.83 KB
/
prob.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#' Check Probability
#'
#' Checks if x is a probability (non-missing dbl between 0 and 1 inclusive with no attributes including names).
#'
#' @inheritParams params
#' @param coerce A flag indicating whether to coerce an integer to a dbl and drop attributes including names.
#'
#' @return An invisible copy of x (if it doesn't throw an error).
#' @seealso \code{\link{check_scalar}}
#' @export
#'
#' @examples
#' check_prob(1, error = FALSE)
#' check_prob(1.1, error = FALSE)
#' check_prob(c(0, 1), error = FALSE)
check_prob <- function(x, coerce = FALSE,
x_name = substitute(x),
error = TRUE) {
lifecycle::deprecate_soft("0.5.1", "check_prob()", NULL,
"Please use chk::chk_dbl() and chk::chk_range() instead.")
x_name <- chk_deparse(x_name)
check_flag_internal(coerce)
check_flag_internal(error)
if(coerce) {
attributes(x) <- NULL
if(is.integer(x))
x <- as.numeric(x)
}
check_scalar(x, values = c(0,1), x_name = x_name, error = error)
}
#' @rdname check_prob
#' @export
check_probability <- function(x, coerce = FALSE,
x_name = substitute(x),
error = TRUE) {
lifecycle::deprecate_soft("0.5.1", "check_probability()", NULL,
"Please use chk::chk_dbl() and chk::chk_range() instead.")
x_name <- chk_deparse(x_name)
check_prob(x, coerce = coerce, x_name = x_name, error = error)
}
#' @rdname check_prob
#' @export
check_prop <- function(x, coerce = FALSE,
x_name = substitute(x),
error = TRUE) {
lifecycle::deprecate_soft("0.5.1", "check_prop()", NULL,
"Please use chk::chk_dbl() and chk::chk_range() instead.")
x_name <- chk_deparse(x_name)
check_prob(x, coerce = coerce, x_name = x_name, error = error)
}