Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the NULL environment?

Tags:

r

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?

like image 629
Alice Ryhl Avatar asked Jul 20 '15 06:07

Alice Ryhl


1 Answers

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.

like image 53
Nick Kennedy Avatar answered Sep 21 '22 15:09

Nick Kennedy