Re: [R] passing arguments via "..."

From: Jonathan P Daily <jdaily_at_usgs.gov>
Date: Tue, 29 Mar 2011 13:56:50 -0400

It is not clear to me exactly what you are looking to do, but if you are trying to check whether an argument has been passed via ..., I have used this convention before.

fun <- function(arg, ...) {
opts <- list(...)
if('opt' %in% names(opts)) # Do something... }

Does that help?



Jonathan P. Daily
Technician - USGS Leetown Science Center 11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,  the thing itself have purpose? Or do we, what's the word... imbue it."

r-help-bounces_at_r-project.org wrote on 03/29/2011 01:47:41 PM:

> [image removed]
>
> [R] passing arguments via "..."
>
> Cable, Samuel B Civ USAF AFMC AFRL/RVBXI
>
> to:
>
> r-help
>
> 03/29/2011 01:51 PM
>
> Sent by:
>
> r-help-bounces_at_r-project.org
>
> I would like to do something like the following:
>
> Fancyhist<-function(x,...) {
>
> # first, process x into xprocess somehow, then ...
>
> if (is.null(breaks)) { # yes, I know this is wrong
> # define the histogram breaks somehow, then call hist:
> hist(xprocess,breaks=breaks,...)
> } else {
> # use breaks give in calling argument
> hist(xprocess,...)
> }
>
> }
>
> But, those of you who know R better than I do have already spotted that
> "is.null(breaks)" just won't work. Neither does "exists" or "missing".
>
> I can think of ways to do this involving new arguments with new names --
> like "histbreaks" or something -- but that seems inelegant.

>
> Is there a way to do what I am trying to do here?

>
> Thanks.
>
> ______________________________________________
> 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. Received on Tue 29 Mar 2011 - 17:58:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 Mar 2011 - 18:20:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive