-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathcoerce.R
More file actions
26 lines (23 loc) · 806 Bytes
/
coerce.R
File metadata and controls
26 lines (23 loc) · 806 Bytes
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
# Used internally by map and flatten.
# Exposed here for testing
coerce <- function(x, type) {
.Call(coerce_impl, x, type)
}
coerce_lgl <- function(x) coerce(x, "logical")
coerce_int <- function(x) coerce(x, "integer")
coerce_dbl <- function(x) coerce(x, "double")
coerce_chr <- function(x) coerce(x, "character")
# Can rewrite after https://github.com/r-lib/rlang/issues/1643
local_deprecation_user_env <- function(
user_env = caller_env(2),
frame = caller_env()
) {
old <- the$deprecation_user_env
the$deprecation_user_env <- user_env
defer(the$deprecation_user_env <- old, frame)
}
# Lightweight equivalent of withr::defer()
defer <- function(expr, env = caller_env(), after = FALSE) {
thunk <- as.call(list(function() expr))
do.call(on.exit, list(thunk, TRUE, after), envir = env)
}