Primitive function in R
Asked Answered
I

0

8

Can someone give me explanation for the below sentence highlighted in Bold.

"Primitive functions are only found in the base package, and since they operate at a low level, they can be more efficient (primitive replacement functions don’t have to make copies), and can have different rules for argument matching (e.g., switch and call). This, however, comes at a cost of behaving differently from all other functions in R. Hence the R core team generally avoids creating them unless there is no other option.

Source Link:http://adv-r.had.co.nz/Functions.html#lexical-scoping

Irrepressible answered 2/7, 2016 at 9:0 Comment(3)
See here on why .Internal is preferred over .Primitive. And, also, as simple example of "closure"s VS "builtin"s, in argument matching, see .subset which is defined as function (x, ...) .Primitive(".subset"): with x = letters[1:3]; wrapsubset = function(x, ...) .subset(x, ...) see (1) .subset(notAnArgument = x, anIndex = 1L) VS wrapsubset(notAnArgument = x, anIndex = 1L) and (2) .subset(1L, x = x) VS wrapsubset(1L, x = x)Chargeable
It may be helpful if you provide more guidance on what you're looking for. What would you like more information on? The R Core Team? The definition of primitive functions in R, or how they behave?Anthropoid
how to view source code for .Prmiitive functions like for example base::prod() would be helpful if an answer would be provided here in the future.Fleam

© 2022 - 2024 — McMap. All rights reserved.