[R] difference between Primitive and Generic

Duncan Murdoch murdoch at stats.uwo.ca
Mon Mar 9 11:29:55 CET 2009


Edna Bell wrote:
> Dear R Gurus:
>
> What is the difference between a Primitive and a Generic, please?
>
>   

They are talking about different things (though both look like 
functions):  generic talks about the user interface, primitive talks 
about the internal implementation.

A generic is a function that will dispatch to a method, based on the 
class (or classes, in the case of S4) of what gets passed to it.

A primitive is a way to implement internal functions in R.   You can 
write generic functions, but you need to modify the R source to write a 
primitive.  Details of the primitive implementation are in the R 
Internals manual.

Duncan Murdoch




More information about the R-help mailing list