[R] plyr package: passing further arguments fail

baptiste auguie ba208 at exeter.ac.uk
Tue Oct 7 16:44:18 CEST 2008


Thanks Hadley, for some reason I didn't see your email until now. It  
works fine with the development version,

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

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

mdply(data. = df, foo1, cc=1, d=2)

I think using . prefixes is a safer option (and possibly more  
consistent with R customs), although that means the current code using  
plyr will have to be modified.

Congratulations on the new ggplot2 release too!

Thanks,

baptiste




On 5 Oct 2008, at 14:39, hadley wickham wrote:

> On Sun, Oct 5, 2008 at 8:02 AM, Auguie, Baptiste  
> <ba208 at exeter.ac.uk> wrote:
>> 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
>
> Unfortunately this bug is R's partial name matching: d = 2 -> data. =
> 2.  You should be able to fix this by manually specifying mdply(data.
> = df, foo1, cc=1, d=2) but there are some bugs in the current version
> that prevent this from happening.  I've fixed this in the development
> version, available from http://github.com/hadley/plyr (click the
> download link)
>
> However, the whole point of plyr is that you should have to think
> about this kind of thing, so I'll revisit my naming scheme - probably
> to use . prefixes instead of suffixes.
>
> Hadley
>
>
> --
> http://had.co.nz/

_____________________________

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag



More information about the R-help mailing list