Rcpp attributes

14
Rcpp Attributes JJ Allaire / Romain François [email protected] @romain_francois [email protected] @rstudioapp jeudi 11 juillet 13

Transcript of Rcpp attributes

Page 2: Rcpp attributes

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

jeudi 11 juillet 13

Page 3: Rcpp attributes

jeudi 11 juillet 13

Page 4: Rcpp attributes

#include <Rcpp.h>

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

jeudi 11 juillet 13

Page 5: Rcpp attributes

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

jeudi 11 juillet 13

Page 6: Rcpp attributes

Why Attributes ?

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

Feature of C++11

jeudi 11 juillet 13

Page 7: Rcpp attributes

No C++11 yet

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

We use pseudo attributes

jeudi 11 juillet 13

Page 8: Rcpp attributes

DependenciesUsingcodefrom anotherpackage

jeudi 11 juillet 13

Page 9: Rcpp attributes

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

Page 10: Rcpp attributes

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

Page 11: Rcpp attributes

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

Custom build configurationExternal libraries

...

jeudi 11 juillet 13

Page 12: Rcpp attributes

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

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

jeudi 11 juillet 13

Page 13: Rcpp attributes

PackagescompileAttributes

Toolsdevtools

RStudio

jeudi 11 juillet 13