[Rd] eapply weirdness/bug

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Feb 18 09:49:13 CET 2005


<Mark.Bravington at csiro.au> writes:

> The following looks like an 'eapply' bug to me:
> 
> t/subtest> e <- new.env()
> t/subtest> e$tempo <- quote( 1+'hi')
> 
> t/subtest> lapply( ls( e), function( x) length( get( x,e)))
> [[1]]
> [1] 3
> # seems reasonable-- e$tempo is a 'call' object of length 3
> 
> t/subtest> eapply( e, length)
> Error in 1 + "hi" : non-numeric argument to binary operator
> 
> t/subtest> eapply( e, length)
> t/subtest> traceback()
> 1: eapply(e, length)
> 
> For some reason 'eapply' seems to *evaluate* objects of mode 'call' (it
> happened with every call-mode object I tried). This shouldn't happen--
> or should it?

It's probably related to the fact that 

> eval(substitute(length(x),list(x=e$tempo)))
Error in 1 + "hi" : non-numeric argument to binary operator

I.e., you cannot construct calls with a mode call argument by
substituting the value of the mode call object. (Got that? Point is
that the substitute returns quote(length(1+"hi")))

It is not clear to me that there is a nice way of fixing this. You
probably need to construct calls of the form FUN(env$var) -- I suspect
that with(env, FUN(var)) or eval(FUN(var), env) would looking for
trouble. Hmm, then again, maybe it could work if FUN gets inserted as
an anonymous function...

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907



More information about the R-devel mailing list