From jmc@research.bell-labs.com  Tue Nov 13 14:24:35 2001
From: jmc@research.bell-labs.com (John Chambers)
Date: Tue, 13 Nov 2001 09:24:35 -0500
Subject: [Rd] Method dispatch in C for primitive functions
Message-ID: <3BF12D23.D62F50B2@research.bell-labs.com>

There is a version of the methods package committed today that does
dispatch in C for these functions.  This should considerably speed up
programs that define methods for these functions (specifically, having
methods should only marginally affect the existing computations for the
same function on basic vectors and objects).

This is the first of several steps needed.  Not quite all primitives are
handled (only those that use DispatchOrEval internally).  And there will
be a few related changes in the methods structure to add a bit more
speed.  A couple of points of strategy should be discussed, preferably
before version 1.4 is frozen.  I'll try to post a note on these  in the
near future.

When writing methods for primitives, it's currently a bit of a trick to
find the formal argument list, since R currently just returns NULL for
args(f) if f is a primitive.  (We may need to make some change here.)

Two that are worth noting are "[" and "[[" (and the corresponding "[<-"
and "[[<-"):

> args(getGeneric("["))
function (x, i = NULL, j = NULL, ..., drop = TRUE) 
NULL
> args(getGeneric("[["))
function (x, i = NULL, ...) 
NULL

The i,j arguments are there so we can, e.g., define methods that
dispatch on the column argument for data-frame-like objects in the
future.

If you're fussing about efficiency, it's slightly better to make sure
you define methods with all the formal arguments (and anyway, it's
cleaner code).

John
-- 
John M. Chambers                  jmc@bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-2681
700 Mountain Avenue, Room 2C-282  fax:    (908)582-3340
Murray Hill, NJ  07974            web: http://www.cs.bell-labs.com/~jmc
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] Method dispatch in C for primitive functions
John Chambers