Dear R Gurus: I'm working slowly through "R Programming for Bioinformatics", which is really interesting! Anyway, my question now is: what determines if a function is a builtin vs. a closure, please? For instance:> typeof(sqrt)[1] "builtin"> typeof(mean)[1] "closure">Thanks, Edna Bell
G'day Edna, On Sat, 14 Mar 2009 23:00:12 -0500 Edna Bell <edna.bell01 at gmail.com> wrote:> Anyway, my question now is: what determines if a function is a > builtin vs. a closure, please?The help page of typeof states that: The possible values are listed in the structure 'TypeTable' in 'src/main/util.c'. Current values are [...] '"closure"' (function) '"special"' and '"builtin"' (basic functions and operators) Which might raise the question what "basic functions" are. But since "basic" and "primitive" are synonyms it is not hard to guess that primitive functions are returning "special" or "builtin"; and the help page of ?is.primitive confirms this. Note, a return value of "special" is possible for a primitive function: R> UseMethod function (generic, object) .Primitive("UseMethod") R> typeof(UseMethod) [1] "special" HTH. Cheers, Berwin
On 15/03/2009 12:00 AM, Edna Bell wrote:> Dear R Gurus: > > I'm working slowly through "R Programming for Bioinformatics", which > is really interesting! > > Anyway, my question now is: what determines if a function is a > builtin vs. a closure, please?Closure is the normal type of function written in R code. The other special types are built in to R; users can't create them except by modifying the R source code. For details see the R Internals manual. Duncan Murdoch> > For instance: >> typeof(sqrt) > [1] "builtin" >> typeof(mean) > [1] "closure" > > Thanks, > Edna Bell > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.