-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathdeprec-utils.R
More file actions
47 lines (43 loc) · 1.19 KB
/
deprec-utils.R
File metadata and controls
47 lines (43 loc) · 1.19 KB
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
#' Generate random sample from a Bernoulli distribution
#'
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' This function was deprecated in purrr 1.0.0 because it's not related to the
#' core purpose of purrr.
#'
#' @param n Number of samples
#' @param p Probability of getting `TRUE`
#' @return A logical vector
#' @keywords internal
#' @export
#' @examples
#' rbernoulli(10)
#' rbernoulli(100, 0.1)
rbernoulli <- function(n, p = 0.5) {
lifecycle::deprecate_warn("1.0.0", "rbernoulli()")
stats::runif(n) > (1 - p)
}
#' Generate random sample from a discrete uniform distribution
#'
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' This function was deprecated in purrr 1.0.0 because it's not related to the
#' core purpose of purrr.
#'
#' @param n Number of samples to draw.
#' @param a,b Range of the distribution (inclusive).
#' @keywords internal
#' @export
#' @examples
#' table(rdunif(1e3, 10))
#' table(rdunif(1e3, 10, -5))
rdunif <- function(n, b, a = 1) {
lifecycle::deprecate_warn("1.0.0", "rdunif()")
stopifnot(is.numeric(a), length(a) == 1)
stopifnot(is.numeric(b), length(b) == 1)
a1 <- min(a, b)
b1 <- max(a, b)
sample(b1 - a1 + 1, n, replace = TRUE) + a1 - 1
}