-
Notifications
You must be signed in to change notification settings - Fork 0
/
rlang.R
61 lines (56 loc) · 1.74 KB
/
rlang.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
57
58
59
60
61
#' Print a warning or message only once using `rlang` functions
#'
#' If you use these you will need to add `"rlang"` to your package dependencies.
#'
#' @param ... Passed to [rlang::warn()] or [rlang::inform()].
#' @inherit common-params
#'
#' @return Invisibly: `TRUE` if the message/warning was shown, `FALSE` otherwise.
#'
#' @doctest
#' oo <- options(onetime.dir = tempdir(check = TRUE))
#' id <- sample(10000L, 1)
#'
#' for (n in 1:3) {
#' @expect warning(regexp = if (n == 1L) "rlang" else NA)
#' onetime_rlang_warn(c("rlang-style warning", i = "Extra info"), id = id)
#' }
#'
#' onetime_reset(id = id)
#' options(oo)
#' @name onetime-rlang
NULL
#' @rdname onetime-rlang
#' @export
onetime_rlang_warn <- function (...,
id = deprecate_calling_package(),
path = default_lockfile_dir(),
expiry = NULL,
without_permission = "warn"
) {
check_rlang()
res <- onetime_do(
rlang::warn(...),
id = id, path = path, expiry = expiry,
without_permission = without_permission
)
return(invisible(! is.null(res)))
}
#' @rdname onetime-rlang
#' @export
onetime_rlang_inform <- function (...,
id = deprecate_calling_package(),
path = default_lockfile_dir(),
expiry = NULL,
without_permission = "warn"
) {
check_rlang()
res <- onetime_do(
rlang::inform(...),
id = id, path = path, expiry = expiry,
# rlang::inform() returns NULL, so change default...
default = "not null",
without_permission = without_permission
)
return(invisible(is.null(res))) # ... and return TRUE if you got NULL
}