I would like to be able to pass named objects in the arguments of a function that have been matched to ellipsis (..., AKA dots) to be made generally available in the execution environment of that function, or of functions executed inside that environment wherever defined, as if the arguments had been typed there.
I tried to do this, for a function, a nested function defined outside of that function, and a nested function defined inside of that function, using list2env(), which is supposed to return the elements of its argument list into the parent.frame() environment, which I understand to be the calling environment. Thus:
# Ellipsis in nested functions
inner_f1<- function(x){list2env(list(...)[-1L]); x + b}
outer_f <- function(x, ...){
list2env(list(...)[-1L])
in01 <- x + a
inner_f2 <- function(x){list2env(list(...)[-1L]); print(ls()); x + c}
in02 <- inner_f2(x)
in03 <- inner_f1(x)
out <- list(in01, in02, in03)
}
outer_f(x=0, a=1, b=2, c=3)
I tried this with and without ...'s in the definitions of the nested functions, but neither works. The desired output would be:
$ in01
[1] 1
$ in02
[1] 2
$ in03
[1] 3
The R help file under "dots" provides no information on passing ... values to interior functions, and the only way it mentions of getting information out of a ... is through the ..(n) method. It refers to "An Introduction to R," but the par example seems to suggest, falsely, that it is sufficient for the interior function to have its own ..., although the par code (not cited there) gets at the contents by doing complicated things to args = list(...)
, and the R language definition also describes the list(...) method. I have not found the idiom substitute(list(...))[-1], frequently used in the R base packages, officially documented anywhere, but in any case neither this nor the eval(substitute(alist(...))) from from "Advanced R"::Nonstandard Evaluation seem to do what I want.
There are a lot of answers to questions about ...s and nested functions here on stackoverflow, but all of the 15 or so that I read seem more specialized than the generalized method I am seeking.