bindrcpp v0.2

0

Monthly downloads

0th

Percentile

An 'Rcpp' Interface to Active Bindings

Provides an easy way to fill an environment with active bindings that call a C++ function.

Readme

bindrcpp Travis-CI Build Status AppVeyor Build Status CRAN\_Status\_Badge

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.

Installation

You can install bindrcpp from github with:

# 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.

#include <Rcpp.h>

// [[Rcpp::depends(bindrcpp)]]
#include <bindrcpp.h>

#include <algorithm>
#include <string>

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:

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:

env$Converting <- "CONVERTING"
#> Error: Binding is read-only.

Functions in bindrcpp

Name Description
reexports Objects exported from other packages
bindrcpp-package bindrcpp: An 'Rcpp' Interface to Active Bindings
init_logging Enable internal logging
No Results!

Last month downloads

Details

Date 2017-06-15
URL https://github.com/krlmlr/bindrcpp, https://krlmlr.github.io/bindrcpp
BugReports https://github.com/krlmlr/bindrcpp/issues
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
Repository CRAN
Date/Publication 2017-06-17 23:52:40 UTC
imports bindr , Rcpp
linkingto plogr
suggests testthat
Contributors RStudio

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/bindrcpp)](http://www.rdocumentation.org/packages/bindrcpp)