MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / RCPP_API_CLASS

Function RCPP_API_CLASS

inst/include/Rcpp/Function.h:33–124  ·  view source on GitHub ↗

* functions */

Source from the content-addressed store, hash-verified

31 * functions
32 */
33 RCPP_API_CLASS(Function_Impl) {
34 public:
35
36 RCPP_GENERATE_CTOR_ASSIGN(Function_Impl)
37
38 Function_Impl(SEXP x){
39 switch( TYPEOF(x) ){
40 case CLOSXP:
41 case SPECIALSXP:
42 case BUILTINSXP:
43 Storage::set__(x);
44 break;
45 default: // #nocov start
46 const char* fmt = "Cannot convert object to a function: "
47 "[type=%s; target=CLOSXP, SPECIALSXP, or "
48 "BUILTINSXP].";
49 throw not_compatible(fmt, Rf_type2char(TYPEOF(x)));
50 } // #nocov end
51 }
52
53 /**
54 * Finds a function. By default, searches from the global environment
55 *
56 * @param name name of the function
57 * @param env an environment where to search the function
58 * @param ns name of the namespace in which to search the function
59 */
60 Function_Impl(const std::string& name) {
61 get_function(name, R_GlobalEnv);
62 }
63
64 Function_Impl(const std::string& name, const SEXP env) {
65 if (!Rf_isEnvironment(env)) {
66 stop("env is not an environment");
67 }
68 get_function(name, env);
69 }
70
71 Function_Impl(const std::string& name, const std::string& ns) {
72#if R_VERSION < R_Version(4,6,0)
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);
76#else
77 Shield<SEXP> env(R_getRegisteredNamespace(ns.c_str()));
78 if (env == R_NilValue)
79 stop("there is no namespace called \"%s\"", ns);
80#endif
81 get_function(name, env);
82 }
83
84 SEXP operator()() const {
85 Shield<SEXP> call(Rf_lang1(Storage::get__()));
86 return Rcpp_fast_eval(call, R_GlobalEnv);
87 }
88
89 template <typename... T>
90 SEXP operator()(const T&... args) const {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected