Site icon R-bloggers

useR!2014 Rcpp11 tutorial

[This article was first published on R Enthusiast and R/C++ hero, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

We are getting close to useR!2014. I hope I’ll see some of you at my tutorial about Rcpp11 in the morning. There are some other pretty useful tutorials as well, so no hard feeling if you don’t come, but if you do want to know about modern R and C++, please join me. Personally I’m happy I’m doing a tutorial because it would have been hard to choose between @MattDowle‘s about data.table, @winston_chang‘s about ggvis and @xieyihui‘s about knitr.

R and C++ fans are lucky this year as you can also choose to learn more conservative R/C++ with @eddelbuettel‘s tutorial about Rcpp in the afternoon. You can even choose to attend both, but my personal recommendations for the afternoon are @hadleywickham‘s about dplyr, @StatGarrett‘s about shiny and @ramnath_vaidya about interactive documents. I wish I was also doing a tutorial in the afternoon so that I would not have to choose.

I’m in the process of preparing the materials. This will be an introductory tutorial so I will focus on simple things, simple enough problems to solve with C++ skills. I’ll walk you through all the way from R solutions to the problems to parallel C++ versions using facilities of C++11. I know, I’ve just said this will be simple and now I’m already talking about parallelism, etc … well that’s the point. This is simple.

To make the most of the tutorial, you’ll need a laptop with a few tools.

install.packages( "Rcpp11" )  

although I would recommend you to get the development version from github.

devtools::install_github( "Rcpp11/Rcpp11" )  

Rcpp11 has no R code or compiled C++ code, so don’t be surprised if you manage to easily and quickly install it. Installing Rcpp11 is not enough. Please keep reading.

devtools::install_github( "Rcpp11/attributes")  

Once you have these tools installed, you can test that everything works together by running that :

writeLines( '  
#include <Rcpp11>

// [[export]]
IntegerVector foo(){  
  return {1, 2, 3} ;
}
', "test.cpp" )  
attributes::sourceCpp("test.cpp")  
foo()  
# [1] 1 2 3

If you get 1, 2, 3 you are ready for the tutorial.

Most of the time during the tutorial, we will be editing .cpp files and compiling them into R with attributes::sourceCpp. I’d recommend you have a text editor that understands C++ but anything will do.

For those of you who live on the console, you might like the scripts from this github repository. I will probably use Rcpp11Script from my console during the tutorial.

To leave a comment for the author, please follow the link and comment on their blog: R Enthusiast and R/C++ hero.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.