[R] understanding as.list(substitute(...()))

peter dalgaard pd@|gd @end|ng |rom gm@||@com
Tue Oct 6 11:23:07 CEST 2020



> On 6 Oct 2020, at 09:22 , Dénes Tóth <toth.denes using kogentum.hu> wrote:
> 
> > foo <- function(...) substitute({...()})
> > foo(abc$de, fg[h], i)
> {
>   pairlist(abc$de, fg[h], i)
> }
> > foo(abc$de, fg[h], , i) # add a missing argument for extra fun
> {
>   as.pairlist(alist(abc$de, fg[h], , i))
> }
> 

The 2nd one here is actually an artifact of deparse(). The result is still a pairlist, just one that pairlist(....) cannot reproduce:

> e <- foo(abc$de, fg[h], , i) 
> e[[2]]
[[1]]
abc$de

[[2]]
fg[h]

[[3]]


[[4]]
i

> deparse(e[[2]])
[1] "as.pairlist(alist(abc$de, fg[h], , i))"
> dput(e[[2]])
as.pairlist(alist(abc$de, fg[h], , i))
> mode(e[[2]])
[1] "pairlist"
> mode(e[[2]][[3]])
[1] "name"

I.e. the list in e[2] contains the missing indicator (an empty name). (I'm slightly puzzled why we need the curlies to trigger a deparse, though) 



-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com



More information about the R-help mailing list