On Thu, Feb 3, 2011 at 1:26 PM, Albert-Jan Roskam <fomcl@yahoo.com> wrote:

> Hi,
>
> I have a function myFun which I want to call multiple times, using
> different
> argument lists.
> myFun("v1", "2009", 1)
> myFun("v2", "2008", 1)
> myFun("q", "2001")
>

Notice that the third call is different, you have 3 args in first two but
only 2 in the third one.  But you have to represent the missing argument
somehow (probably just using the default value explicitly, see args(myFun)
).


> How can I easily do this in R? Should I use mapply?
>
> I unsuccessfully tried something like:
> x <- list(c("v1", "2009", 1), c("v2", "2008", 1), c("q", "2001"))
> mapply(myFun, x)
>

try

mapply(myFun, list("v1", "v2", "q"), list("2009", "2008", "2001"), list(1,1,
SOMETHING))


Regards,
Kenn


>
> Eventually, the argument lists will have to be stored in, and read from, an
> external configuration file (I'm thinking about using yaml), although this
> might
> at this point not yet be relevant.
>
> TIA!
> Cheers!!
> Albert-Jan
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> All right, but apart from the sanitation, the medicine, education, wine,
> public
> order, irrigation, roads, a fresh water system, and public health, what
> have the
> Romans ever done for us?
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@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.
>
>

	[[alternative HTML version deleted]]

