I'm having trouble calling match.call()
from a C++ function. In the example below, the match_call()
C++ function fails at simply forwarding its arguments to match.call()
. What am I missing?
match_call <-
Rcpp::cppFunction(
'
SEXP match_call(SEXP definition, SEXP call) {
Function m("match.call", R_BaseEnv);
return m(definition, call);
}
')
match.call(function(a = 1, b = 2){}, quote(fun(b = 4, 3)))
## fun(a = 3, b = 4)
match_call(function(a = 1, b = 2){}, quote(fun(b = 4, 3)))
## error: could not find function "fun"
As suggested by @nicola, adding a quote()
helps:
return m(definition, Rf_lang2(R_QuoteSymbol, call));
This works, but doesn't explain the mechanisms.