SlideShare a Scribd company logo
Rcpp11
Romain François
romain@r-enthusiasts.com @romain_francois
Rcpp11
• Targets C++11
• Smaller code base (than Rcpp)
• Header only
Rcpp11 useR2014
#include <Rcpp.h>
!
// [[Rcpp::export]]
int foo(){
return 2 ;
}
Rcpp
Rcpp11
0 1 2 3 4
Less complexity -> faster compiles
!
Some examples
NumericVector constructors
// C++ uniform initialization
NumericVector x = {1.0, 2.0, 3.0} ;
!
// init with given size
NumericVector y( 2 ) ; // data is not initialized
NumericVector y( 2, 3.0 ) ; // initialize all to 3.0
!
// fuse several vectors (similar to c in R)
NumericVector z = fuse(x, y) ;
NumericVector z = fuse(x, y, 3.0) ;
create
NumericVector x = {1.0, 2.0, 3.0} ;
!
// old school NumericVector::create (Rcpp style).
NumericVector x = NumericVector::create(1.0, 2.0, 3.0) ;
NumericVector x = NumericVector::create(
_["a"] = 1.0, _["b"] = 2.0, _["c"] = 3.0
) ;
!
!// create as a free function. Rcpp11 style
NumericVector x = create(1.0, 2.0, 3.0) ;
NumericVector x = create(
_["a"] = 1.0, _["b"] = 2.0, _["c"] = 3.0
) ;
sugar
#include <Rcpp11>
!
// [[export]]
NumericVector foo( NumericVector x ){
return sqrt(exp(x)) + 1.0 ;
}
!
/*** R
foo( c(1,2,3) )
# [1] 2.648721 3.718282 5.481689
*/
sapply + lambda
sapply + lambda
#include <Rcpp11>
!
// [[export]]
NumericVector foo( NumericVector x ){
return sapply(x, [](double d){
return exp(d * 2) ;
});
}
x <- 1:3
sapply( x, function(d){
exp(d*2) ;
})
sapply + lambda + …
#include <Rcpp11>
!
// [[export]]
NumericVector foo( NumericVector x ){
auto fun = [](double d, double y, double z){
return exp(d * y) + z ;
} ;
return sapply(x, fun, 3.0, 4.6);
}
x <- 1:3
sapply( x, function(d, y, z){
exp(d*y) + z ;
}, 3.0, 4.6 )
Rcpp11 release cycle
• Available from CRAN:
!
• Evolves quickly. Get it from github
!
• Next Release: 3.1.1 (same time as R 3.1.1)
> install.packages( "Rcpp11" )
> install_github( "Rcpp11/Rcpp11" )
attributes companion package
• Standalone impl of Rcpp attributes
[[Rcpp::export]], sourceCpp, compileAttributes
!
• Only available from github:
> install_github( "Rcpp11/attributes" )
Use Rcpp11 in your package
• Write your .cpp files
#include <Rcpp11>
!
// [[export]]
void foo( … ) { … } // your code
SystemRequirements: C++11
LinkingTo: Rcpp11
library(attributes)
compileAttributes( "mypkg" )
• Express dep on C++11 and Rcpp11 headers
• Generate the boiler plate
Romain François
romain@r-enthusiasts.com @romain_francois
Questions ?

More Related Content

PDF
Rcpp11 genentech
PDF
R/C++ talk at earl 2014
PDF
When RV Meets CEP (RV 2016 Tutorial)
PDF
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
PDF
Activity Recognition Through Complex Event Processing: First Findings
PDF
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
PDF
PDF
A formalization of complex event stream processing
Rcpp11 genentech
R/C++ talk at earl 2014
When RV Meets CEP (RV 2016 Tutorial)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
Activity Recognition Through Complex Event Processing: First Findings
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
A formalization of complex event stream processing

What's hot (20)

PDF
CL metaprogramming
PDF
All I know about rsc.io/c2go
PDF
Libtcc and gwan
DOC
VLSI Sequential Circuits II
PDF
Exploiting vectorization with ISPC
PDF
3 rd animation
DOCX
timingExercise
PPT
FSE 2008
PDF
Go Concurrency
PDF
Clojure+ClojureScript Webapps
PDF
Modern c++ Memory Management
PDF
Golang Channels
PPTX
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
PDF
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
PDF
Why my Go program is slow?
PDF
GoでKVSを書けるのか
PDF
Faster Python, FOSDEM
PDF
C++ Programming - 2nd Study
PDF
C c++-meetup-1nov2017-autofdo
PDF
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
CL metaprogramming
All I know about rsc.io/c2go
Libtcc and gwan
VLSI Sequential Circuits II
Exploiting vectorization with ISPC
3 rd animation
timingExercise
FSE 2008
Go Concurrency
Clojure+ClojureScript Webapps
Modern c++ Memory Management
Golang Channels
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Why my Go program is slow?
GoでKVSを書けるのか
Faster Python, FOSDEM
C++ Programming - 2nd Study
C c++-meetup-1nov2017-autofdo
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Ad

Similar to Rcpp11 useR2014 (20)

PDF
PDF
Rcpp
PDF
R and cpp
PDF
Rcpp: Seemless R and C++
PDF
R and C++
PDF
Rcpp: Seemless R and C++
PDF
Rcpp: Seemless R and C++
PDF
Los Angeles R users group - July 12 2011 - Part 2
PDF
Integrating R with C++: Rcpp, RInside and RProtoBuf
PDF
Extend R with Rcpp!!!
PDF
R で解く FizzBuzz 問題
PDF
[1062BPY12001] Data analysis with R / week 2
PPTX
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
PDF
2015 11-17-programming inr.key
PDF
Introduction to r
PDF
R Programming Homework Help
PDF
Reproducibility with R
PPT
r,rstats,r language,r packages
PPT
SMS Spam Filter Design Using R: A Machine Learning Approach
PDF
Learning R
Rcpp
R and cpp
Rcpp: Seemless R and C++
R and C++
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
Los Angeles R users group - July 12 2011 - Part 2
Integrating R with C++: Rcpp, RInside and RProtoBuf
Extend R with Rcpp!!!
R で解く FizzBuzz 問題
[1062BPY12001] Data analysis with R / week 2
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
2015 11-17-programming inr.key
Introduction to r
R Programming Homework Help
Reproducibility with R
r,rstats,r language,r packages
SMS Spam Filter Design Using R: A Machine Learning Approach
Learning R
Ad

More from Romain Francois (12)

PDF
PDF
dplyr and torrents from cpasbien
PDF
dplyr use case
PDF
PDF
user2015 keynote talk
PDF
SevillaR meetup: dplyr and magrittr
PDF
Data manipulation with dplyr
PDF
Rcpp attributes
PDF
Rcpp is-ready
PDF
Object Oriented Design(s) in R
PDF
RProtoBuf: protocol buffers for R
dplyr and torrents from cpasbien
dplyr use case
user2015 keynote talk
SevillaR meetup: dplyr and magrittr
Data manipulation with dplyr
Rcpp attributes
Rcpp is-ready
Object Oriented Design(s) in R
RProtoBuf: protocol buffers for R

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
cuic standard and advanced reporting.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPT
Teaching material agriculture food technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
NewMind AI Weekly Chronicles - August'25 Week I
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Electronic commerce courselecture one. Pdf
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
cuic standard and advanced reporting.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Teaching material agriculture food technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Spectral efficient network and resource selection model in 5G networks
Mobile App Security Testing_ A Comprehensive Guide.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy

Rcpp11 useR2014

  • 2. Rcpp11 • Targets C++11 • Smaller code base (than Rcpp) • Header only
  • 4. #include <Rcpp.h> ! // [[Rcpp::export]] int foo(){ return 2 ; } Rcpp Rcpp11 0 1 2 3 4 Less complexity -> faster compiles
  • 6. NumericVector constructors // C++ uniform initialization NumericVector x = {1.0, 2.0, 3.0} ; ! // init with given size NumericVector y( 2 ) ; // data is not initialized NumericVector y( 2, 3.0 ) ; // initialize all to 3.0 ! // fuse several vectors (similar to c in R) NumericVector z = fuse(x, y) ; NumericVector z = fuse(x, y, 3.0) ;
  • 7. create NumericVector x = {1.0, 2.0, 3.0} ; ! // old school NumericVector::create (Rcpp style). NumericVector x = NumericVector::create(1.0, 2.0, 3.0) ; NumericVector x = NumericVector::create( _["a"] = 1.0, _["b"] = 2.0, _["c"] = 3.0 ) ; ! !// create as a free function. Rcpp11 style NumericVector x = create(1.0, 2.0, 3.0) ; NumericVector x = create( _["a"] = 1.0, _["b"] = 2.0, _["c"] = 3.0 ) ;
  • 8. sugar #include <Rcpp11> ! // [[export]] NumericVector foo( NumericVector x ){ return sqrt(exp(x)) + 1.0 ; } ! /*** R foo( c(1,2,3) ) # [1] 2.648721 3.718282 5.481689 */
  • 10. sapply + lambda #include <Rcpp11> ! // [[export]] NumericVector foo( NumericVector x ){ return sapply(x, [](double d){ return exp(d * 2) ; }); } x <- 1:3 sapply( x, function(d){ exp(d*2) ; })
  • 11. sapply + lambda + … #include <Rcpp11> ! // [[export]] NumericVector foo( NumericVector x ){ auto fun = [](double d, double y, double z){ return exp(d * y) + z ; } ; return sapply(x, fun, 3.0, 4.6); } x <- 1:3 sapply( x, function(d, y, z){ exp(d*y) + z ; }, 3.0, 4.6 )
  • 12. Rcpp11 release cycle • Available from CRAN: ! • Evolves quickly. Get it from github ! • Next Release: 3.1.1 (same time as R 3.1.1) > install.packages( "Rcpp11" ) > install_github( "Rcpp11/Rcpp11" )
  • 13. attributes companion package • Standalone impl of Rcpp attributes [[Rcpp::export]], sourceCpp, compileAttributes ! • Only available from github: > install_github( "Rcpp11/attributes" )
  • 14. Use Rcpp11 in your package • Write your .cpp files #include <Rcpp11> ! // [[export]] void foo( … ) { … } // your code SystemRequirements: C++11 LinkingTo: Rcpp11 library(attributes) compileAttributes( "mypkg" ) • Express dep on C++11 and Rcpp11 headers • Generate the boiler plate