Skip to content

using list to pass argument to function

2 messages · TyagiAnupam@aol.com, Brian Ripley

#
A brief follow up on an earlier posting. Thanks for the earlier suggestion.

How does it matter if I pass a list or a vector of 
arguments to a function that is written to take individual arguments:

f3args  <- function(a1, a2, a3) { definition}

f1 <- function(b1, b2) {
calculations
n <- samplesize
b<- someestimate
c<- anotherestimate
d <- c(n, b, c)
h <- sapply(rep(d, R), f3args)
}

e <- c(m, n)

k <- sapply(rep(e, R), f1)

Is there a problem with this. Can one pass a vector of arguments to a 
fucntion that is written for individual arguments. What would be a good way 
for doing this?
--Anupam.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Thu, 14 Nov 2002 TyagiAnupam at aol.com wrote:

            
Yes, it does.
It seems to be incomplete, so it's hard to tell what you intended. For
example,  R is undefined. But you are not passing a
second argument to f1.  You do that via an extra argument to sapply.
?do.call,

as in do.call("f1", as.list(e))