[R] Coding C++ in R. What is faster : Using bosst external libraries or R.h header file?

Ian Schiller Ian.Schiller at clinepi.mcgill.ca
Tue Mar 13 14:59:55 CET 2012

Thank you Michael,

Your advices are truly appreciated!


-----Original Message-----
From: R. Michael Weylandt [mailto:michael.weylandt at gmail.com] 
Sent: 13 mars 2012 09:44
To: Ian Schiller
Cc: r-help at r-project.org
Subject: Re: [R] Coding C++ in R. What is faster : Using bosst external libraries or R.h header file?

There will be ever-so-slight performance differences due to implementation differences (I believe R's functions are just a hair slower because they are more exact -- though that may be a comparison with GSL I'm thinking of), but my advice would be to use the RNGs that come with R. They are the best in the business and you'll have the benefit of them being auto-upgraded with each new R release (as well as getting better support from the R lists).

What you really should look into is the Rcpp project. It provides nice wrappers to R's RNG functions and makes the whole porting process worlds easier: e.g., http://dirk.eddelbuettel.com/blog/2011/07/14/

Hope this helps,


On Tue, Mar 13, 2012 at 9:33 AM, Ian Schiller <Ian.Schiller at clinepi.mcgill.ca> wrote:
> Hi everyone,
> I have built an R package and for the sake of speed I have decided to rewrite some part of the code in C++.  In my original R code I use the pnorm, qnorm, rnorm, pgamma, dgamma, rgamma, rbeta and runif function.  First I was thinking in going with the boost libraries, but I noticed the functions described above are available within the R.h header file (or is it Rmath.h?).
> So my question is the following.  Would my code be faster if I install the appropriate boost libraries (distributions) or if I stick with R.h's functions?
> Thanks!
> **********************************************************************
> ********************************************************
> Statistical research assistant,
> Division of Clinical Epidemiology, McGill University Health Center
> Assistant de recherche en statistiques, Département d'Épidémiologie 
> Clinique, Centre Universitaire de Santé Mcgill
> Tel: 514 934 1934 ext. 36925
> Email: 
> ian.schiller at clinepi.mcgill.ca<mailto:ian.schiller at clinepi.mcgill.ca>
>        [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list