How does the dplyr :: n function work?

I am wondering how the n function of dplyr . When evaluating n in dplyr env, all I get is:

 function () { stop("This function should not be called directly") } <environment: namespace:dplyr> 

This may be a stupid question, but where is it defined? How does it work when called inside some other functions? In which env is it hidden?

thanks for the help

+6
source share
1 answer

As far as I understand, dplyr uses a hybrid rating. This means that it will evaluate some parts of the expression in C ++, and others in R. n() is one of the functions that C ++ always processes. This is why a function does nothing directly in R , with the exception of returning an error, since the function is never evaluated by R.

Relevant C++ code can be found on github .

+5
source

Source: https://habr.com/ru/post/1013641/


All Articles