First define a function which is like list() except it ignores all
NULL components. Using that we can write:
list.wo.null <- function(...) list(...)[!sapply(list(...), is.null)]
library(lattice)
myhist <- function(limits) do.call("histogram", list.wo.null(~
height, singer,
endpoints = if (!missing(limits)) limits))
}
myhist()
myhist(c(0, 100))
On 5/27/07, David Lindelof <lindelof at ieee.org>
wrote:> Dear userRs,
>
> Is there a way to explicitly set an argument to a function call as
> missing?
>
> E.g.,
>
> histogram(foo,
> bar,
> endpoints=ifelse(!missing(limits),limits,NA/NULL/whatever)))
>
> In this call I want to set a value to the endpoints argument only if the
> `limits' variable has been set, and leave the defaults otherwise.
>
> The only way I could do it is thus:
>
> if (!missing(limits)) histogram(foo,bar,endpoints=limits)
> else histogram(foo,bar)
>
> Is there a cleaner way?
>
> Kind regards,
>
> David Lindelof
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>