bindrcpp/0000755000176200001440000000000013121340310012037 5ustar liggesusersbindrcpp/inst/0000755000176200001440000000000013000532046013021 5ustar liggesusersbindrcpp/inst/include/0000755000176200001440000000000013120517632014453 5ustar liggesusersbindrcpp/inst/include/bindrcpp_RcppExports.h0000644000176200001440000001307713120517632021006 0ustar liggesusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #ifndef RCPP_bindrcpp_RCPPEXPORTS_H_GEN_ #define RCPP_bindrcpp_RCPPEXPORTS_H_GEN_ #include "bindrcpp_types.h" #include namespace bindrcpp { using namespace Rcpp; namespace { void validateSignature(const char* sig) { Rcpp::Function require = Rcpp::Environment::base_env()["require"]; require("bindrcpp", Rcpp::Named("quietly") = true); typedef int(*Ptr_validate)(const char*); static Ptr_validate p_validate = (Ptr_validate) R_GetCCallable("bindrcpp", "bindrcpp_RcppExport_validate"); if (!p_validate(sig)) { throw Rcpp::function_not_exported( "C++ function with signature '" + std::string(sig) + "' not found in bindrcpp"); } } } inline Environment create_env_string(CharacterVector names, bindrcpp::GETTER_FUNC_STRING fun, bindrcpp::PAYLOAD payload, Environment enclos) { typedef SEXP(*Ptr_create_env_string)(SEXP,SEXP,SEXP,SEXP); static Ptr_create_env_string p_create_env_string = NULL; if (p_create_env_string == NULL) { validateSignature("Environment(*create_env_string)(CharacterVector,bindrcpp::GETTER_FUNC_STRING,bindrcpp::PAYLOAD,Environment)"); p_create_env_string = (Ptr_create_env_string)R_GetCCallable("bindrcpp", "bindrcpp_create_env_string"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_create_env_string(Shield(Rcpp::wrap(names)), Shield(Rcpp::wrap(fun)), Shield(Rcpp::wrap(payload)), Shield(Rcpp::wrap(enclos))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline Environment populate_env_string(Environment env, CharacterVector names, bindrcpp::GETTER_FUNC_STRING fun, bindrcpp::PAYLOAD payload) { typedef SEXP(*Ptr_populate_env_string)(SEXP,SEXP,SEXP,SEXP); static Ptr_populate_env_string p_populate_env_string = NULL; if (p_populate_env_string == NULL) { validateSignature("Environment(*populate_env_string)(Environment,CharacterVector,bindrcpp::GETTER_FUNC_STRING,bindrcpp::PAYLOAD)"); p_populate_env_string = (Ptr_populate_env_string)R_GetCCallable("bindrcpp", "bindrcpp_populate_env_string"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_populate_env_string(Shield(Rcpp::wrap(env)), Shield(Rcpp::wrap(names)), Shield(Rcpp::wrap(fun)), Shield(Rcpp::wrap(payload))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline Environment create_env_symbol(CharacterVector names, bindrcpp::GETTER_FUNC_SYMBOL fun, bindrcpp::PAYLOAD payload, Environment enclos) { typedef SEXP(*Ptr_create_env_symbol)(SEXP,SEXP,SEXP,SEXP); static Ptr_create_env_symbol p_create_env_symbol = NULL; if (p_create_env_symbol == NULL) { validateSignature("Environment(*create_env_symbol)(CharacterVector,bindrcpp::GETTER_FUNC_SYMBOL,bindrcpp::PAYLOAD,Environment)"); p_create_env_symbol = (Ptr_create_env_symbol)R_GetCCallable("bindrcpp", "bindrcpp_create_env_symbol"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_create_env_symbol(Shield(Rcpp::wrap(names)), Shield(Rcpp::wrap(fun)), Shield(Rcpp::wrap(payload)), Shield(Rcpp::wrap(enclos))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline Environment populate_env_symbol(Environment env, CharacterVector names, bindrcpp::GETTER_FUNC_SYMBOL fun, bindrcpp::PAYLOAD payload) { typedef SEXP(*Ptr_populate_env_symbol)(SEXP,SEXP,SEXP,SEXP); static Ptr_populate_env_symbol p_populate_env_symbol = NULL; if (p_populate_env_symbol == NULL) { validateSignature("Environment(*populate_env_symbol)(Environment,CharacterVector,bindrcpp::GETTER_FUNC_SYMBOL,bindrcpp::PAYLOAD)"); p_populate_env_symbol = (Ptr_populate_env_symbol)R_GetCCallable("bindrcpp", "bindrcpp_populate_env_symbol"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_populate_env_symbol(Shield(Rcpp::wrap(env)), Shield(Rcpp::wrap(names)), Shield(Rcpp::wrap(fun)), Shield(Rcpp::wrap(payload))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } } #endif // RCPP_bindrcpp_RCPPEXPORTS_H_GEN_ bindrcpp/inst/include/bindrcpp_types.h0000644000176200001440000000245713120503113017646 0ustar liggesusers#ifndef _bindrcpp_bindrcpp_types_H_ #define _bindrcpp_bindrcpp_types_H_ #include #include namespace bindrcpp { struct PAYLOAD { void* p; explicit PAYLOAD(void* p_) : p(p_) {}; }; typedef SEXP (*GETTER_FUNC_STRING)(const Rcpp::String& name, bindrcpp::PAYLOAD payload); typedef SEXP (*GETTER_FUNC_SYMBOL)(const Rcpp::Symbol& name, bindrcpp::PAYLOAD payload); } namespace Rcpp { using namespace bindrcpp; template <> inline SEXP wrap(const PAYLOAD& payload) { return List::create(XPtr(new PAYLOAD(payload))); } template <> inline SEXP wrap(const GETTER_FUNC_STRING& fun) { return List::create(XPtr(new GETTER_FUNC_STRING(fun))); } template <> inline SEXP wrap(const GETTER_FUNC_SYMBOL& fun) { return List::create(XPtr(new GETTER_FUNC_SYMBOL(fun))); } template <> inline PAYLOAD as(SEXP x) { List xl = x; XPtr xpayload(static_cast(xl[0])); return *xpayload.get(); } template <> inline GETTER_FUNC_STRING as(SEXP x) { List xl = x; XPtr xfun(static_cast(xl[0])); return *xfun.get(); } template <> inline GETTER_FUNC_SYMBOL as(SEXP x) { List xl = x; XPtr xfun(static_cast(xl[0])); return *xfun.get(); } } #endif bindrcpp/inst/include/bindrcpp.h0000644000176200001440000000037613000545715016433 0ustar liggesusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #ifndef RCPP_bindrcpp_H_GEN_ #define RCPP_bindrcpp_H_GEN_ #include "bindrcpp_RcppExports.h" #endif // RCPP_bindrcpp_H_GEN_ bindrcpp/tests/0000755000176200001440000000000013116236337013222 5ustar liggesusersbindrcpp/tests/testthat.R0000644000176200001440000000007413116236337015206 0ustar liggesuserslibrary(testthat) library(bindrcpp) test_check("bindrcpp") bindrcpp/tests/testthat/0000755000176200001440000000000013121340310015041 5ustar liggesusersbindrcpp/tests/testthat/test-create.R0000644000176200001440000000154213120503113017407 0ustar liggesuserscontext("create") test_that("cpp_create_environment()", { env_cb <- cpp_create_environment(letters, "toupper") env <- env_cb$env expect_equal(env$a, "A") expect_equal(env$x, "X") expect_null(env$X) expect_equal(length(ls(env)), length(letters)) expect_error(env$a <- "a", "read-only") }) test_that("cpp_create_environment() with inheritance", { env_cb <- cpp_create_environment(letters, "toupper") env <- env_cb$env env2_cb <- cpp_create_environment(LETTERS, "tolower", parent = env) env2 <- env2_cb$env expect_equal(get("a", env2), "A") expect_equal(get("x", env2), "X") expect_null(env2$a) expect_null(env2$x) expect_equal(env2$B, "b") expect_equal(env2$Y, "y") expect_equal(length(ls(env2)), length(letters)) expect_error(env2$B <- "B", "read-only") expect_error(env2$a <- "a", NA) expect_equal(get("a", env2), "a") }) bindrcpp/src/0000755000176200001440000000000013120571702012640 5ustar liggesusersbindrcpp/src/Makevars0000644000176200001440000000004513120571702014333 0ustar liggesusersPKG_CPPFLAGS = -I../inst/include -I. bindrcpp/src/create.cpp0000644000176200001440000000331513120571702014611 0ustar liggesusers#include #include #include using namespace Rcpp; Environment pkg_env = Environment::namespace_env("bindrcpp"); Function R_create_env("create_env", pkg_env); Function R_populate_env("populate_env", pkg_env); Function R_callback_string("callback_string", pkg_env); Function R_callback_symbol("callback_symbol", pkg_env); // [[Rcpp::interfaces(cpp)]] // [[Rcpp::export(create_env_string)]] Environment create_env_string_imp(CharacterVector names, bindrcpp::GETTER_FUNC_STRING fun, bindrcpp::PAYLOAD payload, Environment enclos) { using namespace bindrcpp; LOG_VERBOSE << payload.p; return R_create_env(names, R_callback_string, fun, payload, _[".enclos"] = enclos); } // [[Rcpp::interfaces(cpp)]] // [[Rcpp::export(populate_env_string)]] Environment populate_env_string_imp(Environment env, CharacterVector names, bindrcpp::GETTER_FUNC_STRING fun, bindrcpp::PAYLOAD payload) { using namespace bindrcpp; LOG_VERBOSE << payload.p; return R_populate_env(env, names, R_callback_string, fun, payload); } // [[Rcpp::interfaces(cpp)]] // [[Rcpp::export(create_env_symbol)]] Environment create_env_symbol_imp(CharacterVector names, bindrcpp::GETTER_FUNC_SYMBOL fun, bindrcpp::PAYLOAD payload, Environment enclos) { using namespace bindrcpp; LOG_VERBOSE << payload.p; return R_create_env(names, R_callback_symbol, fun, payload, _[".enclos"] = enclos); } // [[Rcpp::interfaces(cpp)]] // [[Rcpp::export(populate_env_symbol)]] Environment populate_env_symbol_imp(Environment env, CharacterVector names, bindrcpp::GETTER_FUNC_SYMBOL fun, bindrcpp::PAYLOAD payload) { using namespace bindrcpp; LOG_VERBOSE << payload.p; return R_populate_env(env, names, R_callback_symbol, fun, payload); } bindrcpp/src/plogr.cpp0000644000176200001440000000056613120571702014476 0ustar liggesusers#include //' Enable internal logging //' //' Log entries, depending on the log level, will be printed to the standard //' error stream. //' //' @param log_level A character value, one of "WARN", "INFO", "DEBUG", "VERB", //' or "NONE". //' //' @keywords internal // [[Rcpp::export]] void init_logging(const std::string& log_level) { plog::init_r(log_level); } bindrcpp/src/Makevars.win0000644000176200001440000000004513120571702015127 0ustar liggesusersPKG_CPPFLAGS = -I../inst/include -I. bindrcpp/src/RcppExports.cpp0000644000176200001440000002557213120571702015650 0ustar liggesusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #include "../inst/include/bindrcpp.h" #include "../inst/include/bindrcpp_types.h" #include #include #include using namespace Rcpp; // create_env_string_imp Environment create_env_string_imp(CharacterVector names, bindrcpp::GETTER_FUNC_STRING fun, bindrcpp::PAYLOAD payload, Environment enclos); static SEXP bindrcpp_create_env_string_imp_try(SEXP namesSEXP, SEXP funSEXP, SEXP payloadSEXP, SEXP enclosSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< CharacterVector >::type names(namesSEXP); Rcpp::traits::input_parameter< bindrcpp::GETTER_FUNC_STRING >::type fun(funSEXP); Rcpp::traits::input_parameter< bindrcpp::PAYLOAD >::type payload(payloadSEXP); Rcpp::traits::input_parameter< Environment >::type enclos(enclosSEXP); rcpp_result_gen = Rcpp::wrap(create_env_string_imp(names, fun, payload, enclos)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP bindrcpp_create_env_string_imp(SEXP namesSEXP, SEXP funSEXP, SEXP payloadSEXP, SEXP enclosSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(bindrcpp_create_env_string_imp_try(namesSEXP, funSEXP, payloadSEXP, enclosSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // populate_env_string_imp Environment populate_env_string_imp(Environment env, CharacterVector names, bindrcpp::GETTER_FUNC_STRING fun, bindrcpp::PAYLOAD payload); static SEXP bindrcpp_populate_env_string_imp_try(SEXP envSEXP, SEXP namesSEXP, SEXP funSEXP, SEXP payloadSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< Environment >::type env(envSEXP); Rcpp::traits::input_parameter< CharacterVector >::type names(namesSEXP); Rcpp::traits::input_parameter< bindrcpp::GETTER_FUNC_STRING >::type fun(funSEXP); Rcpp::traits::input_parameter< bindrcpp::PAYLOAD >::type payload(payloadSEXP); rcpp_result_gen = Rcpp::wrap(populate_env_string_imp(env, names, fun, payload)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP bindrcpp_populate_env_string_imp(SEXP envSEXP, SEXP namesSEXP, SEXP funSEXP, SEXP payloadSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(bindrcpp_populate_env_string_imp_try(envSEXP, namesSEXP, funSEXP, payloadSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // create_env_symbol_imp Environment create_env_symbol_imp(CharacterVector names, bindrcpp::GETTER_FUNC_SYMBOL fun, bindrcpp::PAYLOAD payload, Environment enclos); static SEXP bindrcpp_create_env_symbol_imp_try(SEXP namesSEXP, SEXP funSEXP, SEXP payloadSEXP, SEXP enclosSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< CharacterVector >::type names(namesSEXP); Rcpp::traits::input_parameter< bindrcpp::GETTER_FUNC_SYMBOL >::type fun(funSEXP); Rcpp::traits::input_parameter< bindrcpp::PAYLOAD >::type payload(payloadSEXP); Rcpp::traits::input_parameter< Environment >::type enclos(enclosSEXP); rcpp_result_gen = Rcpp::wrap(create_env_symbol_imp(names, fun, payload, enclos)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP bindrcpp_create_env_symbol_imp(SEXP namesSEXP, SEXP funSEXP, SEXP payloadSEXP, SEXP enclosSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(bindrcpp_create_env_symbol_imp_try(namesSEXP, funSEXP, payloadSEXP, enclosSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // populate_env_symbol_imp Environment populate_env_symbol_imp(Environment env, CharacterVector names, bindrcpp::GETTER_FUNC_SYMBOL fun, bindrcpp::PAYLOAD payload); static SEXP bindrcpp_populate_env_symbol_imp_try(SEXP envSEXP, SEXP namesSEXP, SEXP funSEXP, SEXP payloadSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< Environment >::type env(envSEXP); Rcpp::traits::input_parameter< CharacterVector >::type names(namesSEXP); Rcpp::traits::input_parameter< bindrcpp::GETTER_FUNC_SYMBOL >::type fun(funSEXP); Rcpp::traits::input_parameter< bindrcpp::PAYLOAD >::type payload(payloadSEXP); rcpp_result_gen = Rcpp::wrap(populate_env_symbol_imp(env, names, fun, payload)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP bindrcpp_populate_env_symbol_imp(SEXP envSEXP, SEXP namesSEXP, SEXP funSEXP, SEXP payloadSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(bindrcpp_populate_env_symbol_imp_try(envSEXP, namesSEXP, funSEXP, payloadSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // init_logging void init_logging(const std::string& log_level); RcppExport SEXP bindrcpp_init_logging(SEXP log_levelSEXP) { BEGIN_RCPP Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const std::string& >::type log_level(log_levelSEXP); init_logging(log_level); return R_NilValue; END_RCPP } // callback_string SEXP callback_string(Symbol name, bindrcpp::GETTER_FUNC_STRING fun, bindrcpp::PAYLOAD payload); RcppExport SEXP bindrcpp_callback_string(SEXP nameSEXP, SEXP funSEXP, SEXP payloadSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< Symbol >::type name(nameSEXP); Rcpp::traits::input_parameter< bindrcpp::GETTER_FUNC_STRING >::type fun(funSEXP); Rcpp::traits::input_parameter< bindrcpp::PAYLOAD >::type payload(payloadSEXP); rcpp_result_gen = Rcpp::wrap(callback_string(name, fun, payload)); return rcpp_result_gen; END_RCPP } // callback_symbol SEXP callback_symbol(Symbol name, bindrcpp::GETTER_FUNC_SYMBOL fun, bindrcpp::PAYLOAD payload); RcppExport SEXP bindrcpp_callback_symbol(SEXP nameSEXP, SEXP funSEXP, SEXP payloadSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< Symbol >::type name(nameSEXP); Rcpp::traits::input_parameter< bindrcpp::GETTER_FUNC_SYMBOL >::type fun(funSEXP); Rcpp::traits::input_parameter< bindrcpp::PAYLOAD >::type payload(payloadSEXP); rcpp_result_gen = Rcpp::wrap(callback_symbol(name, fun, payload)); return rcpp_result_gen; END_RCPP } // do_test_create_environment List do_test_create_environment(CharacterVector names, String xform, Environment parent); RcppExport SEXP bindrcpp_do_test_create_environment(SEXP namesSEXP, SEXP xformSEXP, SEXP parentSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< CharacterVector >::type names(namesSEXP); Rcpp::traits::input_parameter< String >::type xform(xformSEXP); Rcpp::traits::input_parameter< Environment >::type parent(parentSEXP); rcpp_result_gen = Rcpp::wrap(do_test_create_environment(names, xform, parent)); return rcpp_result_gen; END_RCPP } // validate (ensure exported C++ functions exist before calling them) static int bindrcpp_RcppExport_validate(const char* sig) { static std::set signatures; if (signatures.empty()) { signatures.insert("Environment(*create_env_string)(CharacterVector,bindrcpp::GETTER_FUNC_STRING,bindrcpp::PAYLOAD,Environment)"); signatures.insert("Environment(*populate_env_string)(Environment,CharacterVector,bindrcpp::GETTER_FUNC_STRING,bindrcpp::PAYLOAD)"); signatures.insert("Environment(*create_env_symbol)(CharacterVector,bindrcpp::GETTER_FUNC_SYMBOL,bindrcpp::PAYLOAD,Environment)"); signatures.insert("Environment(*populate_env_symbol)(Environment,CharacterVector,bindrcpp::GETTER_FUNC_SYMBOL,bindrcpp::PAYLOAD)"); } return signatures.find(sig) != signatures.end(); } // registerCCallable (register entry points for exported C++ functions) RcppExport SEXP bindrcpp_RcppExport_registerCCallable() { R_RegisterCCallable("bindrcpp", "bindrcpp_create_env_string", (DL_FUNC)bindrcpp_create_env_string_imp_try); R_RegisterCCallable("bindrcpp", "bindrcpp_populate_env_string", (DL_FUNC)bindrcpp_populate_env_string_imp_try); R_RegisterCCallable("bindrcpp", "bindrcpp_create_env_symbol", (DL_FUNC)bindrcpp_create_env_symbol_imp_try); R_RegisterCCallable("bindrcpp", "bindrcpp_populate_env_symbol", (DL_FUNC)bindrcpp_populate_env_symbol_imp_try); R_RegisterCCallable("bindrcpp", "bindrcpp_RcppExport_validate", (DL_FUNC)bindrcpp_RcppExport_validate); return R_NilValue; } static const R_CallMethodDef CallEntries[] = { {"bindrcpp_create_env_string_imp", (DL_FUNC) &bindrcpp_create_env_string_imp, 4}, {"bindrcpp_populate_env_string_imp", (DL_FUNC) &bindrcpp_populate_env_string_imp, 4}, {"bindrcpp_create_env_symbol_imp", (DL_FUNC) &bindrcpp_create_env_symbol_imp, 4}, {"bindrcpp_populate_env_symbol_imp", (DL_FUNC) &bindrcpp_populate_env_symbol_imp, 4}, {"bindrcpp_init_logging", (DL_FUNC) &bindrcpp_init_logging, 1}, {"bindrcpp_callback_string", (DL_FUNC) &bindrcpp_callback_string, 3}, {"bindrcpp_callback_symbol", (DL_FUNC) &bindrcpp_callback_symbol, 3}, {"bindrcpp_do_test_create_environment", (DL_FUNC) &bindrcpp_do_test_create_environment, 3}, {"bindrcpp_RcppExport_registerCCallable", (DL_FUNC) &bindrcpp_RcppExport_registerCCallable, 0}, {NULL, NULL, 0} }; RcppExport void R_init_bindrcpp(DllInfo *dll) { R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } bindrcpp/src/test.cpp0000644000176200001440000000462013120571702014325 0ustar liggesusers#include #include #include #include #include using namespace Rcpp; using namespace bindrcpp; // [[Rcpp::export(rng = FALSE)]] SEXP callback_string(Symbol name, bindrcpp::GETTER_FUNC_STRING fun, bindrcpp::PAYLOAD payload) { LOG_VERBOSE << type2name(name); LOG_VERBOSE << payload.p; String name_string = name.c_str(); name_string.set_encoding(CE_NATIVE); return fun(name_string, payload); } // [[Rcpp::export(rng = FALSE)]] SEXP callback_symbol(Symbol name, bindrcpp::GETTER_FUNC_SYMBOL fun, bindrcpp::PAYLOAD payload) { LOG_VERBOSE << type2name(name); LOG_VERBOSE << payload.p; return fun(name, payload); } class CallbackTester { enum { MAGIC = 20161014 }; const int magic; public: CallbackTester() : magic(MAGIC) { LOG_VERBOSE; } ~CallbackTester() { LOG_VERBOSE; } static SEXP tolower_static(const Rcpp::String& name, PAYLOAD payload) { LOG_VERBOSE << payload.p; CallbackTester* this_ = reinterpret_cast(payload.p); return this_->tolower(name); } static SEXP toupper_static(const Rcpp::String& name, PAYLOAD payload) { LOG_VERBOSE << payload.p; CallbackTester* this_ = reinterpret_cast(payload.p); return this_->toupper(name); } private: SEXP tolower(Rcpp::String name) { LOG_VERBOSE << magic; if (magic != MAGIC) stop("payload lost"); std::string name_string = name; std::transform(name_string.begin(), name_string.end(), name_string.begin(), ::tolower); return CharacterVector(name_string); } SEXP toupper(Rcpp::String name) { LOG_VERBOSE << magic; if (magic != MAGIC) stop("payload lost"); std::string name_string = name; std::transform(name_string.begin(), name_string.end(), name_string.begin(), ::toupper); return CharacterVector(name_string); } }; // [[Rcpp::export]] List do_test_create_environment(CharacterVector names, String xform, Environment parent) { CallbackTester* pc = new CallbackTester; List ret = List::create(_["callback"] = XPtr(pc)); if (xform == "tolower") { ret["env"] = bindrcpp::create_env_string( names, &CallbackTester::tolower_static, PAYLOAD(pc), parent); } else if (xform == "toupper") { ret["env"] = bindrcpp::create_env_string( names, &CallbackTester::toupper_static, PAYLOAD(pc), parent); } else stop("unknown xform"); return ret; } bindrcpp/NAMESPACE0000644000176200001440000000030113000545715013264 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(create_env) export(populate_env) importFrom(Rcpp,sourceCpp) importFrom(bindr,create_env) importFrom(bindr,populate_env) useDynLib(bindrcpp) bindrcpp/NEWS.md0000644000176200001440000000220313120563702013145 0ustar liggesusers# bindrcpp 0.2 (2017-06-15) - Fixed very rare segmentation fault due to missing protection of function arguments in autogenerated boilerplate code. - Fix compilation errors on FreeBSD due to use of nonstandard Make features (#5). - Native symbol registration added by Rcpp. # bindrcpp 0.1 (2016-12-08) Initial CRAN release. ## Exported C++ functions - `create_env_string()` creates an environment with active bindings, with names given as a character vector. Access of these bindings triggers a call to a C++ function with a fixed signature (`GETTER_FUNC_STRING`); this call contains the name of the binding (as character) and an arbitrary payload (`PAYLOAD`, essentially a wrapped `void*`). - `create_env_symbol()` is similar, the callback function accepts the name of the binding as symbol instead of character (`GETTER_FUNC_SYMBOL`). - `populate_env_string()` and `populate_env_symbol()` populate an existing environment instead of creating a new one. - Use `LinkingTo: bindrcpp` and `#include ` to access these functions from your package. ## Exported R functions - Reexported from `bindr`: `create_env()` and `populate_env()`. bindrcpp/R/0000755000176200001440000000000013120222457012252 5ustar liggesusersbindrcpp/R/bindrcpp-package.R0000644000176200001440000000166113023247251015574 0ustar liggesusers#' @details Use `LinkingTo: bindrcpp` in `DESCRIPTION` and #' `#include ` in your C++ headers and/or modules to access the #' C++ functions provided by this package: #' #' - `create_env_string()` creates an environment with active bindings, with #' names given as a character vector. Access of these bindings triggers a #' call to a C++ function with a fixed signature (`GETTER_FUNC_STRING`); #' this call contains the name of the binding (as character) and an arbitrary #' payload (`PAYLOAD`, essentially a wrapped `void*`). #' - `create_env_symbol()` is similar, the callback function accepts the name of #' the binding as symbol instead of character (`GETTER_FUNC_SYMBOL`). #' - `populate_env_string()` and `populate_env_symbol()` populate an existing #' environment instead of creating a new one. "_PACKAGE" #' @useDynLib bindrcpp #' @importFrom Rcpp sourceCpp #' @importFrom bindr create_env populate_env NULL bindrcpp/R/test.R0000644000176200001440000000020113000545715013347 0ustar liggesuserscpp_create_environment <- function(names, xform, parent = parent.frame()) { do_test_create_environment(names, xform, parent) } bindrcpp/R/RcppExports.R0000644000176200001440000000207313120222457014670 0ustar liggesusers# Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #' Enable internal logging #' #' Log entries, depending on the log level, will be printed to the standard #' error stream. #' #' @param log_level A character value, one of "WARN", "INFO", "DEBUG", "VERB", #' or "NONE". #' #' @keywords internal init_logging <- function(log_level) { invisible(.Call('bindrcpp_init_logging', PACKAGE = 'bindrcpp', log_level)) } callback_string <- function(name, fun, payload) { .Call('bindrcpp_callback_string', PACKAGE = 'bindrcpp', name, fun, payload) } callback_symbol <- function(name, fun, payload) { .Call('bindrcpp_callback_symbol', PACKAGE = 'bindrcpp', name, fun, payload) } do_test_create_environment <- function(names, xform, parent) { .Call('bindrcpp_do_test_create_environment', PACKAGE = 'bindrcpp', names, xform, parent) } # Register entry points for exported C++ functions methods::setLoadAction(function(ns) { .Call('bindrcpp_RcppExport_registerCCallable', PACKAGE = 'bindrcpp') }) bindrcpp/R/bindr.R0000644000176200001440000000007513022267766013512 0ustar liggesusers#' @export bindr::create_env #' @export bindr::populate_env bindrcpp/README.md0000644000176200001440000000507113023247251013334 0ustar liggesusers bindrcpp [![Travis-CI Build Status](https://travis-ci.org/krlmlr/bindrcpp.svg?branch=master)](https://travis-ci.org/krlmlr/bindrcpp) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/krlmlr/bindrcpp?branch=master&svg=true)](https://ci.appveyor.com/project/krlmlr/bindrcpp) [![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/bindrcpp)](https://cran.r-project.org/package=bindrcpp) =============================================================================================================================================================================================================================================================================================================================================================================================================================== It's easy to create active bindings in R via [`makeActiveBinding()`](https://www.rdocumentation.org/packages/base/versions/3.3.1/topics/bindenv). This package faciliates the creation of active bindings that link back to C++ code. It provides an interface that allows binding several identifiers in an environment to the same C++ function, which is then called with the name (and a payload) as argument. Installation ------------ You can install bindrcpp from github with: ``` r # install.packages("devtools") devtools::install_github("krlmlr/bindrcpp") ``` Example ------- The following C++ module exports a function `test_tolower_bindings()` that creates active bindings that return the binding name in lowercase. ``` cpp #include // [[Rcpp::depends(bindrcpp)]] #include #include #include using namespace Rcpp; using namespace bindrcpp; SEXP tolower_callback(const String& name, PAYLOAD) { std::string name_string = name; std::transform(name_string.begin(), name_string.end(), name_string.begin(), ::tolower); return CharacterVector(name_string); } // [[Rcpp::export]] SEXP test_tolower_bindings(CharacterVector names, Environment parent) { // We don't pass any payload here return bindrcpp::create_env_string( names, &tolower_callback, PAYLOAD(NULL), parent); } ``` This function can be called from R: ``` r env <- test_tolower_bindings(c("Converting", "to", "LOWERCASE"), .GlobalEnv) ls(env) #> [1] "Converting" "LOWERCASE" "to" env$Converting #> [1] "converting" env$to #> [1] "to" env$LOWERCASE #> [1] "lowercase" env$y #> NULL ``` The bindings are read-only: ``` r env$Converting <- "CONVERTING" #> Error: Binding is read-only. ``` bindrcpp/MD50000644000176200001440000000222713121340310012352 0ustar liggesusers52470b405afa4c0d5172a439604ad6bd *DESCRIPTION d3d2f503f5c96ac395a270e7c295ec0b *LICENSE 3a9c92677932609677f9a6370d097c29 *NAMESPACE 876a0477e3f61e936ef0fdb7211fdaaf *NEWS.md 7ddf9467cba4519d4692e5f6f1795806 *R/RcppExports.R 1ce0e6f00f32e2d0765fb57749317ec9 *R/bindr.R b04097e5dbb70ea2d7bf5b0fee8acb46 *R/bindrcpp-package.R 2cdf48ce2f31adb3aea16cd398507126 *R/test.R 35837e0fbb8b9a53760fd747e6bdac89 *README.md ebff110d87c1681eda6f30b93fa7ffde *inst/include/bindrcpp.h fc7eea695d0dd9253a05637f8d7601da *inst/include/bindrcpp_RcppExports.h 51590efce84ef7ff9bf547c265cd66bf *inst/include/bindrcpp_types.h aaf228a83c0e8d48ab132a5523ab5ccf *man/bindrcpp-package.Rd fed1d0a4957c37ae234ceb655095f717 *man/init_logging.Rd bfebf612b38c0d8e41f4f3449c290aa7 *man/reexports.Rd 3a3c839566f06a1eb4cb3c960b7cab62 *src/Makevars 3a3c839566f06a1eb4cb3c960b7cab62 *src/Makevars.win 9436f19309a6dcd8adc4fd9cb33930fd *src/RcppExports.cpp 5917fdf0957beca52727bb02dad6a90f *src/create.cpp 6492f645509837fe7c735958d71079d3 *src/plogr.cpp 4c5fafc9e32aea31f70fd316f4f0af9e *src/test.cpp 9d12bc91cc42c506ca4ac9a2184614b8 *tests/testthat.R 56632f0010990dc5ab5d734dfe763b95 *tests/testthat/test-create.R bindrcpp/DESCRIPTION0000644000176200001440000000152313121340310013546 0ustar liggesusersPackage: bindrcpp Title: An 'Rcpp' Interface to Active Bindings Description: Provides an easy way to fill an environment with active bindings that call a C++ function. Authors@R: c( person("Kirill", "Müller", role = c("aut", "cre"), email = "krlmlr+r@mailbox.org"), person("RStudio", role = "cph") ) Version: 0.2 Date: 2017-06-15 URL: https://github.com/krlmlr/bindrcpp, https://krlmlr.github.io/bindrcpp BugReports: https://github.com/krlmlr/bindrcpp/issues Imports: Rcpp, bindr Suggests: testthat LinkingTo: Rcpp, plogr RoxygenNote: 6.0.1 LazyData: true License: MIT + file LICENSE Encoding: UTF-8 NeedsCompilation: yes Packaged: 2017-06-15 20:53:22 UTC; muelleki Author: Kirill Müller [aut, cre], RStudio [cph] Maintainer: Kirill Müller Repository: CRAN Date/Publication: 2017-06-17 23:52:40 UTC bindrcpp/man/0000755000176200001440000000000013120517632012626 5ustar liggesusersbindrcpp/man/bindrcpp-package.Rd0000644000176200001440000000302213120517632016304 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bindrcpp-package.R \docType{package} \name{bindrcpp-package} \alias{bindrcpp} \alias{bindrcpp-package} \title{bindrcpp: An 'Rcpp' Interface to Active Bindings} \description{ Provides an easy way to fill an environment with active bindings that call a C++ function. } \details{ Use \code{LinkingTo: bindrcpp} in \code{DESCRIPTION} and \code{#include } in your C++ headers and/or modules to access the C++ functions provided by this package: \itemize{ \item \code{create_env_string()} creates an environment with active bindings, with names given as a character vector. Access of these bindings triggers a call to a C++ function with a fixed signature (\code{GETTER_FUNC_STRING}); this call contains the name of the binding (as character) and an arbitrary payload (\code{PAYLOAD}, essentially a wrapped \code{void*}). \item \code{create_env_symbol()} is similar, the callback function accepts the name of the binding as symbol instead of character (\code{GETTER_FUNC_SYMBOL}). \item \code{populate_env_string()} and \code{populate_env_symbol()} populate an existing environment instead of creating a new one. } } \seealso{ Useful links: \itemize{ \item \url{https://github.com/krlmlr/bindrcpp} \item \url{https://krlmlr.github.io/bindrcpp} \item Report bugs at \url{https://github.com/krlmlr/bindrcpp/issues} } } \author{ \strong{Maintainer}: Kirill Müller \email{krlmlr+r@mailbox.org} Other contributors: \itemize{ \item RStudio [copyright holder] } } bindrcpp/man/reexports.Rd0000644000176200001440000000073013022263750015150 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/bindr.R \docType{import} \name{reexports} \alias{reexports} \alias{create_env} \alias{reexports} \alias{populate_env} \title{Objects exported from other packages} \keyword{internal} \description{ These objects are imported from other packages. Follow the links below to see their documentation. \describe{ \item{bindr}{\code{\link[bindr]{create_env}}, \code{\link[bindr]{populate_env}}} }} bindrcpp/man/init_logging.Rd0000644000176200001440000000064713120517632015575 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/RcppExports.R \name{init_logging} \alias{init_logging} \title{Enable internal logging} \usage{ init_logging(log_level) } \arguments{ \item{log_level}{A character value, one of "WARN", "INFO", "DEBUG", "VERB", or "NONE".} } \description{ Log entries, depending on the log level, will be printed to the standard error stream. } \keyword{internal} bindrcpp/LICENSE0000644000176200001440000000004513022263750013057 0ustar liggesusersYEAR: 2016 COPYRIGHT HOLDER: RStudio