Any way to access function installed by makeActiveBinding? Any way to access function installed by makeActiveBinding? r r

Any way to access function installed by makeActiveBinding?


With a bit of noodling around in envir.c, I can get this to work:

#include <Rcpp.h>using namespace Rcpp ;#define HASHSIZE(x)      LENGTH(x)#define HASHVALUE(x)    TRUELENGTH(x)// [[Rcpp::export]]SEXP get_binding_fun( std::string name, Environment env){    SEXP symbol = Rf_install( name.c_str() );    SEXP tab = HASHTAB(env) ;    SEXP c = PRINTNAME(symbol);    // finding the hash code for the symbol    int hashcode = HASHVALUE(c) % HASHSIZE(tab);    // get the value there from the hash table    SEXP res = CAR( VECTOR_ELT(tab, hashcode ) ) ;    return res ;}

Save this into a .cpp file, sourceCpp it and use it with this R code:

> makeActiveBinding("x", function() runif(2), .GlobalEnv)> get_binding_fun("x", .GlobalEnv)# function ()# runif(2)