Alice Ryhl
Alice Ryhl

Reputation: 4229

What is the NULL environment?

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?

Upvotes: 8

Views: 790

Answers (1)

Nick Kennedy
Nick Kennedy

Reputation: 12640

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 their formals(), body(), and environment() are all NULL.

Upvotes: 9

Related Questions