Rcpp attributes

Preview:

Citation preview

int add( int a, int b){ return a + b ;}

jeudi 11 juillet 13

jeudi 11 juillet 13

#include <Rcpp.h>

// [[Rcpp::export]]int add( int a, int b){ return a + b ;}

jeudi 11 juillet 13

> sourceCpp( "add.cpp" )> add( 1, 2 )[1] 3

jeudi 11 juillet 13

Why Attributes ?

[[omp::parallel]]void somefunction(){}

Feature of C++11

jeudi 11 juillet 13

No C++11 yet

// [[Rcpp::export]]void somefunction(){}

We use pseudo attributes

jeudi 11 juillet 13

DependenciesUsingcodefrom anotherpackage

jeudi 11 juillet 13

Dependencies

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

// [[Rcpp::export]]arma::mat eye(int dim, double value){ using namespace arma ; mat x = value * eye<mat>(dim,dim); return x ;}

jeudi 11 juillet 13

Dependencies

> sourceCpp( "eye.cpp" )> eye( 4, 12 ) [,1] [,2] [,3] [,4][1,] 12 0 0 0[2,] 0 12 0 0[3,] 0 0 12 0[4,] 0 0 0 12

jeudi 11 juillet 13

// [[Rcpp::plugin(foo)]]

Custom build configurationExternal libraries

...

jeudi 11 juillet 13

Plugins#include <Rcpp.h>// [[Rcpp::plugin(cpp11)]]

// [[Rcpp::export]]IntegerVector example(){ IntegerVector x = {1, 2, 3} ; return x ;}

jeudi 11 juillet 13

PackagescompileAttributes

Toolsdevtools

RStudio

jeudi 11 juillet 13

Recommended