Dear R Core Team, I learnt approx. two years ago in this mailing list that one can use the following "trick" to get a (dotted pair)list of the ellipsis arguments inside a function: `substitute(...())` Now my problem is that I can not find any occurrence of this call within the R source - the most frequent solution there is `substitute(list(...))[-1L] ` I would like to know if: 1) substitute(...()) is a trick or a feature in the language; 2) it will be supported in the future; 3) when (in which R version) it was introduced. A hint on where to look for the machinery in the R source would be also appreciated. Regards, Denes
Note that substitute(...()) and substitute(someFunc(...))[-1] give slightly different results, the former a pairlist and the latter a call. > str((function(...)substitute(...()))(stop(1),stop(2),stop(3))) Dotted pair list of 3 $ : language stop(1) $ : language stop(2) $ : language stop(3) > str((function(...)substitute(someFunc(...))[-1])(stop(1),stop(2),stop(3))) language stop(1)(stop(2), stop(3)) The ...() idiom has been around for a long time, but more recently (slightly after R-3.4.0?) the ...elt(n) and ...length() functions were introduced so you don't have to use it much. I don't see a ...names() function that would give the names of the ... arguments - names(substitute(...())). Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Mar 12, 2020 at 2:09 AM D?nes T?th <toth.denes at kogentum.hu> wrote:> Dear R Core Team, > > I learnt approx. two years ago in this mailing list that one can use the > following "trick" to get a (dotted pair)list of the ellipsis arguments > inside a function: > > `substitute(...())` > > Now my problem is that I can not find any occurrence of this call within > the R source - the most frequent solution there is > `substitute(list(...))[-1L] ` > > I would like to know if: > 1) substitute(...()) is a trick or a feature in the language; > 2) it will be supported in the future; > 3) when (in which R version) it was introduced. > > A hint on where to look for the machinery in the R source would be also > appreciated. > > Regards, > Denes > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >[[alternative HTML version deleted]]
On 3/12/20 4:06 PM, William Dunlap wrote:> Note that substitute(...()) and substitute(someFunc(...))[-1] give > slightly different results, the former a pairlist and the latter a call. > ? > str((function(...)substitute(...()))(stop(1),stop(2),stop(3))) > ? Dotted pair list of 3 > ? ?$ : language stop(1) > ? ?$ : language stop(2) > ? ?$ : language stop(3) > ? > > str((function(...)substitute(someFunc(...))[-1])(stop(1),stop(2),stop(3))) > ? ?language stop(1)(stop(2), stop(3))Yes, I am aware of this difference. In my use cases, the ...() form gives the result that I prefer (a pairlist).> > The ...() idiom has been around for a long time, but more recently > (slightly after R-3.4.0?) the ...elt(n) and ...length() functions were > introduced so you don't have to use it much.Yes, I know both.> I don't see a ...names() > function that would give the names of the ... arguments - > names(substitute(...())).Exactly, this is a frequent use case. Occasionally I use it in other cases as well where I deliberately do not want to evaluate the arguments passed as dots. What I am most interested in is whether this is a 'trick' or a legal use of a (rather unadvertised) feature of the language.> > Bill Dunlap > TIBCO Software > wdunlap tibco.com <http://tibco.com> > > > On Thu, Mar 12, 2020 at 2:09 AM D?nes T?th <toth.denes at kogentum.hu > <mailto:toth.denes at kogentum.hu>> wrote: > > Dear R Core Team, > > I learnt approx. two years ago in this mailing list that one can use > the > following "trick" to get a (dotted pair)list of the ellipsis arguments > inside a function: > > `substitute(...())` > > Now my problem is that I can not find any occurrence of this call > within > the R source - the most frequent solution there is > `substitute(list(...))[-1L] ` > > I would like to know if: > 1) substitute(...()) is a trick or a feature in the language; > 2) it will be supported in the future; > 3) when (in which R version) it was introduced. > > A hint on where to look for the machinery in the R source would be also > appreciated. > > Regards, > Denes > > ______________________________________________ > R-devel at r-project.org <mailto:R-devel at r-project.org> mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >