[Rd] An artifact of base being namespace

Saikat DebRoy saikat at stat.wisc.edu
Fri Oct 10 18:00:51 MEST 2003


On Friday, Oct 10, 2003, at 08:35 US/Eastern, Martin Maechler wrote:

>>>>>> "Saikat" == Saikat DebRoy <saikat at stat.wisc.edu>
>>>>>>     on Thu, 9 Oct 2003 11:41:01 -0400 writes:
>
>     Saikat> This is most problematic when you are creating a
>     Saikat> generic for an existing function in base (as you
>     Saikat> very well could for log). This often makes the
>     Saikat> ability to make new generics out of existing
>     Saikat> functions somewhat useless.
>
> Assuming you're right, I'm much less sure that this consequence
> has been intended in all situations.  But I'd need to see
> concrete examples to understand your last sentence.
>

Here is an example of what I was saying.

 > setClass('foo', representation(x='numeric'))
[1] "foo"
 > setMethod('log', signature(x='foo', base="missing"),
+  function(x, base) callGeneric(x at x))
[1] "log"
 > setMethod('log', 'foo', function(x, base)
+  callGeneric(x at x, base))
[1] "log"
 > log(new('foo', x=100))
[1] 4.60517
 > log10(new('foo', x=100))
Error in log(x, base) : Non-numeric argument to mathematical function
 >

This means that if I create a generic for 'log', I should also create a 
generic for each function in base that makes a call to 'log'. That is 
not what I expected.



More information about the R-devel mailing list