我很好奇为什么purrr::map_*
函数族尽管是tidyverse
的一部分,但在评估映射函数之前不支持通过展开引用其dots
来进行准引用?
library(tidyverse)
library(rlang)
set.seed(1)
dots <- quos(digits = 2L)
# this obviously won't work
purrr::map_chr(rnorm(5L),
~ format(.x, !!!dots))
#> Error in !dots: invalid argument type
# I'm confused why this does not work
purrr::map_chr(rnorm(5L),
~ format(.x, ...),
!!!dots)
#> Error in !dots: invalid argument type
# Finally, this works
eval_tidy(expr(
purrr::map_chr(rnorm(5L),
~ format(.x, ...),
!!!dots)
))
#> [1] "1.5" "0.39" "-0.62" "-2.2" "1.1"
这段代码是使用 reprex包 (v0.2.0) 于2019-01-31创建的。
rlang::call2
那样)。 - mjktfw