Primitive {base}R Documentation

Look Up a Primitive Function

Description

.Primitive looks up by name a ‘primitive’ (internally implemented) function.

Usage

.Primitive(name)

Arguments

name

name of the R function.

Details

The advantage of .Primitive over .Internal functions is the potential efficiency of argument passing, and that positional matching can be used where desirable, e.g. in switch. For more details, see the ‘R Internals’ manual.

All primitive functions are in the base namespace.

You should not set attributes on primitive functions. This now signals a deprecation warning and will become illegal (via error), soon.

This function is almost never used: `name` or, more carefully, get(name, envir = baseenv()) work equally well and do not depend on knowing which functions are primitive (which does change as R evolves).

See Also

is.primitive showing that primitive functions come in two types (typeof), .Internal.

Examples

mysqrt <- .Primitive("sqrt")
 ## be careful, this changes base R's sqrt() {until restarting R} !
try(structure(mysqrt, comment = "primitive function")) # deprecation warning; soon an error

.Internal # this one *must* be primitive!
`if` # need backticks

[Package base version 4.4.3 Index]