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 ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili at gmail.com | Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130816/51a3c001/attachment.html>
[Rcpp-devel] Using Rcpp in a package only as an option?
5 messages · Dirk Eddelbuettel, Tal Galili, Romain Francois +1 more
On 16 August 2013 at 19:36, Tal Galili wrote:
| 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) If the code is used (ie not commented out) then it must be compiled and linked and you must have the depends. Your only choice may be to author two packages 'foo' and 'fooFast' where only the latter uses Rcpp. Dirk | Thoughts? | | With regards, | Tal | | | | | | ----------------Contact | Details:------------------------------------------------------- | Contact me: Tal.Galili at gmail.com |? | Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | | www.r-statistics.com (English) | ---------------------------------------------------------------------------------------------- | | | ---------------------------------------------------------------------- | _______________________________________________ | Rcpp-devel mailing list | Rcpp-devel at lists.r-forge.r-project.org | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
I suspected that this is the case. Will do - thanks. ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili at gmail.com | Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ----------------------------------------------------------------------------------------------
On Fri, Aug 16, 2013 at 7:52 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
On 16 August 2013 at 19:36, Tal Galili wrote: | 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) If the code is used (ie not commented out) then it must be compiled and linked and you must have the depends. Your only choice may be to author two packages 'foo' and 'fooFast' where only the latter uses Rcpp. Dirk | Thoughts? | | With regards, | Tal | | | | | | ----------------Contact | Details:------------------------------------------------------- | Contact me: Tal.Galili at gmail.com | | Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | | www.r-statistics.com (English) | ---------------------------------------------------------------------------------------------- | | | ---------------------------------------------------------------------- | _______________________________________________ | Rcpp-devel mailing list | Rcpp-devel at lists.r-forge.r-project.org | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel -- Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130816/871eccc6/attachment.html>
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
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.
And even if you're not distributing from source, telling (windows) users to install rtools and then use install_github is not a big barrier. Hadley
Chief Scientist, RStudio http://had.co.nz/