I probably need to be more specific.  What confuses me is not the use
of substitute, but the parenthesis after the dots.  It clearly works
and I can make guesses as to why but it is definitely not obvious.
The following function gives the same final result but I can
understand what is happening.

dots <- function (...) {
   exprs <- substitute(list(...))
   as.list(exprs[-1])
}

In the original,     dots <- function(...) as.list(substitute(...())),
   Does ...() get parsed in a special way?

Tim

On Tue, 6 Oct 2020 at 05:30, Bert Gunter <bgunter.4...@gmail.com> wrote:
>
> You need to understand what substitute() does -- see ?substitute and/or a 
> tutorial on "R computing on the language" or similar.
>
> Here is a simple example that may clarify:
>
> > dots <- function(...) as.list(substitute(...()))
> > dots(log(foo))
> [[1]]
> log(foo)  ## a call, a language object
>
> > dots2 <- function(...) as.list(...)
> > dots2(log(foo))
> Error in as.list(...) : object 'foo' not found
> ## substitute() does not evaluate its argument; as.list() does
>
> Cheers,
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and 
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Mon, Oct 5, 2020 at 1:37 PM Tim Taylor <tim.tay...@hiddenelephants.co.uk> 
> wrote:
>>
>> Could someone explain what is happening with the ...() of the
>> following function:
>>
>> dots <- function(...) as.list(substitute(...()))
>>
>> I understand what I'm getting as a result but not why.   ?dots and
>> ?substitute leave me none the wiser.
>>
>> regards
>> Tim
>>
>> ______________________________________________
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to