[Rcpp-devel] Using Rcpp in a package only as an option?

Romain Francois romain at r-enthusiasts.com
Fri Aug 16 19:21:43 CEST 2013


Le 16/08/13 18:36, Tal Galili a écrit :
> Hello dear list members,
>
> Following previous correspondence, I wish to use an Rcpp function inside
> a package I'm authoring.
> However, I do not wish to force the user to install Rcpp, and if he does
> not wish to do so, I want to let him "fall back" on an R written
> function (which is 20-40 times slower, but it works).
> Looking at this Vignettes:
> http://cran.rstudio.com/web/packages/Rcpp/vignettes/Rcpp-package.pdf
> I see that including Rcpp in a package require the use of "depends" in
> DESCRIPTION.
> Is there a way to have Rcpp as "Suggests", and to later use "require"
> when loading the package, to decide if to load the Rcpp function or the
> R function?
> (alternatively, I could have a separate package only for that function,
> but that feels a bit like a "hack" to me)
>
> Thoughts?
>
> With regards,
> Tal

The only way you could do that would be if your code was compiled at 
runtime, e.g. you'd have calls to sourceCpp in your R code, which is 
pretty inefficient and would require more work for you to setup.

In most cases your package is going to be distributed as binary anyway, 
so CRAN compiled it, and CRAN compiled Rcpp, so there should be nothing 
to worry.

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30

R Graph Gallery: http://gallery.r-enthusiasts.com

blog:            http://blog.r-enthusiasts.com
|- http://bit.ly/13SrjxO : highlight 0.4.2
`- http://bit.ly/10X94UM : Mobile version of the graph gallery



More information about the Rcpp-devel mailing list