Mind the gap: Finding the text of C++ code called by an R function

133 Views Asked by At

I would like to find the text of the C++ code called by an R function, specifically, the function "_dplyr_summarise_impl" which is called by summarise_impl. Even more specifically, I would like to find the bit of code that precedes that which returns the error message"

Error in summarise_impl(.data, dots) :
Evaluation error: argument "yes" is missing, with no default.

I presume that the "yes" in the code above varies, but that it is supplied by some other bit of dplyr or the related tidyverse, as none of my code possess a "yes" argument to be missing. Or it might be base R code called by tidyverse code. But in either case, there is a gap between the error message and the last function I could see with traceback, caused, I am guessing, by traceback being unable to find its way through called C++ code. I am hypothesizing that if I can find the code that was supposed to supply the "yes" argument, that will tell me what is going wrong. But there is a gap between the last function that traceback supplies and the error message above. I am looking for help in bridging that gap.

It now appears to me that this is a standard error message for some version of eval, either base or tidyverse, that is called either by _dplyr_summarise_impl, or some function that it calls. Many, perhaps all, of the dplyr major verbs have an unexported function of the form <function>_impl, and all of these functions return error messages very similar to the one previously cited. So I suspect they may be calling a common error message process.

I just found the text of _dplyr_summarise_impl here, in dplyr/src/RcppExports.cpp. That takes me one step closer, but I don't know enough C++ to know which of these lines is most likely to be calling the function that calls the error. Guess I'll read the C++ chapter in Advanced R next.

// summarise_impl
SEXP summarise_impl(DataFrame df, QuosureList dots);
RcppExport SEXP _dplyr_summarise_impl(SEXP dfSEXP, SEXP dotsSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< DataFrame >::type df(dfSEXP);
    Rcpp::traits::input_parameter< QuosureList >::type dots(dotsSEXP);
    rcpp_result_gen = Rcpp::wrap(summarise_impl(df, dots));
    return rcpp_result_gen;
END_RCPP
} 
0

There are 0 best solutions below