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 .
source share