22 #ifndef Rcpp_Function_h
23 #define Rcpp_Function_h
39 Function_Impl(SEXP x){
47 const char* fmt =
"Cannot convert object to a function: "
48 "[type=%s; target=CLOSXP, SPECIALSXP, or "
50 throw not_compatible(fmt, Rf_type2char(TYPEOF(x)));
61 Function_Impl(
const std::string& name) {
62 get_function(name, R_GlobalEnv);
65 Function_Impl(
const std::string& name,
const SEXP env) {
66 if (!Rf_isEnvironment(env)) {
67 stop(
"env is not an environment");
69 get_function(name, env);
72 Function_Impl(
const std::string& name,
const std::string& ns) {
73 Shield<SEXP> env(Rf_findVarInFrame(R_NamespaceRegistry, Rf_install(ns.c_str())));
74 if (env == R_UnboundValue) {
75 stop(
"there is no namespace called \"%s\"", ns);
77 get_function(name, env);
80 SEXP operator()()
const {
85 #include <Rcpp/generated/Function__operator.h>
90 SEXP environment()
const {
91 SEXP fun = Storage::get__() ;
92 if( TYPEOF(fun) != CLOSXP ) {
93 throw not_a_closure(Rf_type2char(TYPEOF(fun)));
102 return BODY( Storage::get__() ) ;
109 void get_function(
const std::string& name,
const SEXP env) {
110 SEXP nameSym = Rf_install( name.c_str() );
115 SEXP invoke(SEXP args_, SEXP env)
const {
#define RCPP_GENERATE_CTOR_ASSIGN(__CLASS__)
Function_Impl< PreserveStorage > Function
RCPP_API_CLASS(DottedPair_Impl)
SEXP Rcpp_fast_eval(SEXP expr, SEXP env)
void NORET stop(const char *fmt, Args &&... args)