I've found a temporary workaround that may be useful to nail down the problem 
(if problem there is),

If I quote() each additional argument to be passed to fun., everything works 
fine:

df <- data.frame(a=1:10 , b=1:10)

foo1 <- function(a, b, cc=0, d=0){
        a + b + cc + d
}

mdply(df, foo1, cc=1, d=2) # obscure (to me) failure
mdply(df, foo1, quote(cc=1), quote(d=2))

Best wishes,

baptiste

________________________________________
From: Auguie, Baptiste
Sent: 05 October 2008 14:02
To: r-help@r-project.org
Cc: [EMAIL PROTECTED]
Subject: plyr package: passing further arguments fail

Dear list and Hadley,

The new plyr package seems to provide a clean and consistent way to apply a 
function on several arguments. However, I don't understand why the following 
example does not work like the standard mapply,

library(plyr)
df <- data.frame(a=1:10 , b=1:10)

foo1 <- function(a, b, cc=0, d=0){
        a + b + cc + d
}

mdply(df, foo1, cc=1) # fine

mdply(df, foo1, d=1) # fails
mdply(df, foo1, cc=1, d=2) # fails

mapply(foo1, a=df$a, b=df$b, MoreArgs=list(cc=1))
mapply(foo1, a=df$a, b=df$b, MoreArgs=list(d=1))
mapply(foo1, a=df$a, b=df$b, MoreArgs=list(cc=1, d=2))

Best regards,

baptiste

______________________________________________
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.

Reply via email to