If I check the environment of the sqrt
function, I get NULL
:
> environment(sqrt)
NULL
On the other hand, the function split
which is also found in the base package has the environment:
> environment(split)
<environment: namespace:base>
Why does these two functions have different environments, and what does the NULL environment mean?
sqrt
is a primitive function and has no R code. Per Hadley Wickham's advanced R page:
Primitive functions
There is one exception to the rule that functions have three components. Primitive functions, like
sum()
, call C code directly with.Primitive(
) and contain no R code. Therefore theirformals()
,body()
, andenvironment()
are allNULL
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With