[R] turning R expressions into functions?

Bert Gunter gunter.berton at gene.com
Mon Jul 23 23:45:28 CEST 2012


Bill:

Is there some reason to prefer your "odd idiom" to match.call, perhaps
as as.list(match.call()), as proposed by Hadley?

-- Bert

On Mon, Jul 23, 2012 at 2:25 PM, William Dunlap <wdunlap at tibco.com> wrote:
> list(...) evaluates the things in ...
> E.g.,
>    > f0 <- function(x, ...) list(...)
>    > f0(1, warning("Hmm"), stop("Oops"), cat("some output\n"))[[2]]
>    Error in f0(1, warning("Hmm"), stop("Oops"), cat("some output\n")) : Oops
>    In addition: Warning message:
>    In f0(1, warning("Hmm"), stop("Oops"), cat("some output\n")) : Hmm
>
> You can use the odd idiom substitute(...()) to get the unevaluated ... arguments:
>    > f1 <- function(x, ...) substitute(...())
>    > f1(1, warning("Hmm"), stop("Oops"), cat("some output\n"))
>    [[1]]
>    warning("Hmm")
>
>    [[2]]
>    stop("Oops")
>
>    [[3]]
>    cat("some output\n")
>
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
>> Behalf Of S Ellison
>> Sent: Monday, July 23, 2012 2:12 PM
>> To: Jochen Voß
>> Cc: r-help at r-project.org
>> Subject: Re: [R] turning R expressions into functions?
>>
>> >> One of the things I would love to add to my package would be the
>> >> ability to compare more than two expressions in one call.  But
>> >> unfortunately, I haven't found out so far whether (and if so, how) it
>> >> is possible to extract the elements of a "..." object without
>> >> evaluating them.
>> >
>> >Have a look at match.call.
>>
>> ... or use
>> dotlist <- list(...)
>>
>> to get a list of everything included in ...
>>
>> S Ellison
>>
>> *****************************************************************
>> **
>> This email and any attachments are confidential. Any use...{{dropped:8}}
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> 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 at r-project.org mailing list
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list