Adding ... to a function specification usually comes with a big
downside: any mispelled or extraneous arguments will be silently
ignored. This package explores an approach to making ... safer, by
inspecting its contents and warning if any elements were not evaluated.
In the long run, this code is likely to live elsewhere (hopefully R-core might be interested so we could make it part of base R). This repository tracks the current state of the experiment.
Thanks to Jenny Bryan for the idea, and Lionel Henry for the heart of the implementation.
devtools::install_gituhb("hadley/ellipsis")ellipsis comes with two functions that illustrates how we can make
functionals (which pass ... to another argument) and S3 generics
(which pass ... on to their methods) safer. safe_map() and
safe_median() warn if you supply arguments that are never evaluated.
library(ellipsis)
x <- safe_map(iris[1:4], median, na.mr = TRUE)
#> Warning: Some components of ... were not used: na.mr
x <- safe_map(iris[1:4], median, na.rm = TRUE)
x <- safe_map(iris[1:4], median, 2)
x <- safe_map(iris[1:4], median, 2, 3)
#> Warning: Some components of ... were not used: ..2
x <- safe_median(1:10)
x <- safe_median(1:10, FALSE)
#> Warning: Some components of ... were not used: ..1
x <- safe_median(1:10, na.rm = FALSE)
x <- safe_median(1:10, na.mr = TRUE)
#> Warning: Some components of ... were not used: na.mrThe top-level function handles all evaluation failures so that this only
generates a single warning (not one warning from safe_map() and four
from safe_median())
x <- safe_map(iris[1:4], safe_median, na.mr = TRUE)
#> Warning: Some components of ... were not used: na.mr