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
.Internal
is preferred over.Primitive
. And, also, as simple example of "closure"s VS "builtin"s, in argument matching, see.subset
which is defined asfunction (x, ...) .Primitive(".subset")
: withx = letters[1:3]; wrapsubset = function(x, ...) .subset(x, ...)
see (1).subset(notAnArgument = x, anIndex = 1L)
VSwrapsubset(notAnArgument = x, anIndex = 1L)
and (2).subset(1L, x = x)
VSwrapsubset(1L, x = x)
– Chargeable.Prmiitive
functions like for examplebase::prod()
would be helpful if an answer would be provided here in the future. – Fleam