The documentation shows that this is possible:
fn <- function(a = 1, b = 2) rlang::fn_fmls()
fn()
$a
[1] 1
$b
[1] 2
I would like to have rlang::fn_fmls()
within a function, and return the same structure for arguments within the current scope.
Expected behaviour:
x <- function(a, b){
rlang::fn_fmls(fn = rlang::current_fn())
}
x(a = 1, b = 2)
$a
[1] 1
$b
[1] 2
Actual behaviour:
x <- function(a, b){
rlang::fn_fmls(fn = rlang::current_fn())
}
x(a = 1, b = 2)
$a
$b
Another approach I've tried is:
x <- function(a, b){
tmp <- base::match.call() %>%
base::as.list()
tmp %>%
stringr::str_detect('x') %>%
purrr::discard(tmp, .)
}
x(a = 1, b = 2)
$a
[1] 1
$b
[1] 2
Is there a way with rlang to get my intended results?
Are you looking for
rlang::call_args
?If you are looking for the default arguments to be "filled in" then you could do something like:
Which produces the following behavior:
Created on 2020-10-03 by the reprex package (v0.3.0)