The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
It’s easy to create active bindings in R via makeActiveBinding()
.
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.
It is recommended to use the newer _wrapped
functions
that support passing an arbitrary Rcpp::List
as payload.
This allows to store an Rcpp::XPtr
to a C++ object in that
list. The XPtr
then will be released when the payload is
garbage-collected, and the C++ object will be destroyed.
You can install bindrcpp from github with:
# install.packages("devtools")
::install_github("krlmlr/bindrcpp") devtools
The following C++ module exports a function
test_tolower_bindings()
that creates active bindings that
return the binding name in lowercase.
#include <Rcpp.h>
// [[Rcpp::depends(bindrcpp)]]
#include <bindrcpp.h>
#include <algorithm>
#include <string>
using namespace Rcpp;
using namespace bindrcpp;
(const String& name, PAYLOAD) {
SEXP tolower_callbackstd::string name_string = name;
std::transform(name_string.begin(), name_string.end(), name_string.begin(), ::tolower);
return CharacterVector(name_string);
}
// [[Rcpp::export]]
(CharacterVector names, Environment parent) {
SEXP test_tolower_bindings// We don't pass any payload here
return bindrcpp::create_env_string(
, &tolower_callback, PAYLOAD(NULL), parent);
names}
This function can be called from R:
<- test_tolower_bindings(c("Converting", "to", "LOWERCASE"), .GlobalEnv)
env ls(env)
#> [1] "Converting" "LOWERCASE" "to"
$Converting
env#> [1] "converting"
$to
env#> [1] "to"
$LOWERCASE
env#> [1] "lowercase"
$y
env#> NULL
The bindings are read-only:
$Converting <- "CONVERTING"
env#> Error: Binding is read-only.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.