Re: [Rd] eapply weirdness/bug

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Fri 18 Feb 2005 - 19:49:13 EST

<Mark.Bravington@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@biostat.ku.dk)             FAX: (+45) 35327907

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri Feb 18 19:00:34 2005

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:02:53 EST