Simon
2013-Nov-03 03:35 UTC
[Rd] How to make an R package that uses Boost.Thread, qualified to be published on CRAN or shared by the most
Hi, Recently, I made an R package that used the C++ library Boost.Thread (http://www.boost.org/doc/libs/1_54_0/doc/html/thread.html) for multithreading. Previously, I have posted a question at stackoverflow (http://stackoverflow.com/questions/19651954/is-it-possible-to-build-an-r-package-which-use-rcpp-and-boost-thread-on-http), and I also asked at rcpp-devel (http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-November/006777.html). Dirk Eddelbuettel suggested me ask here. After some tries on win-builder and some research on CRAN, there are still some doubts: 1) For my package to be accepted by CRAN, I am not so sure if it is acceptable to let users to install Boost library themselves? If not, are there any solutions? I found there are some third party external software or libraries used by other R packages, such as OpenMP and gtk, some of which have corresponding R packages, but there are little discuss about Boost. (I now know there are some other ways to host my package, but I think CRAN is more straight forward, though it may be stricter.) 2) As I said in my question at stackoverflow (http://stackoverflow.com/questions/19651954/is-it-possible-to-build-an-r-package-which-use-rcpp-and-boost-thread-on-http), I have tried MAKE variable BOOSTLIB on win-builder (http://win-builder.r-project.org/), It is OK for header-only Boost libraries. I am not sure whether it is OK for separately-compiled libraries such as Boost.Thread, after many fails. Is it possible? Are there any special variables or path for Boost.Thread? May I suppose that it is acceptable for 1) if there are, or at least for header-only Boost libraies? (There are an R package called BH provides header-only Boost libraries, but BOOSTLIB make me imagine something else.) Simon PS: Below are the source files and results of my tries for exploring BOOSTLIB on win-builder, please forgive me use win-builder as a test machine, so I post my questions here. The test package is derived from command Rscript -e "Rcpp.package.skeleton()", below just lists some modifications by me. The outputs in 00install.out are too long to be pasted here. ------------------------------- rcpp_hello_world.cpp ------------------------------- #include "rcpp_hello_world.h" #include "boost/lambda/lambda.hpp" #include <iostream> #include <iterator> #include <algorithm> #include <vector> #include "boost/thread.hpp" void wait(int seconds) { boost::this_thread::sleep(boost::posix_time::seconds(seconds)); } void thread() { for (int i = 0; i < 5; i++) { wait(1); std::cout << i << std::endl; } } SEXP rcpp_hello_world(){ using namespace Rcpp ; using namespace boost::lambda; std::vector<int> a; a.push_back(1); a.push_back(2); // std::for_each( a.begin(), a.end(), _1 = 1); boost::thread t(thread); t.join(); return wrap(a); } ------------------------------- Makevars.win (try 1: try to find if there is a file called libboost_thread*) ------------------------------- ## Use the R_HOME indirection to support installations of multiple R version ## PKG_CXXFLAGS = `$(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()"` PKG_CPPFLAGS = -I${BOOSTLIB} PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()") ${BOOSTLIB}/lib/libboost_thread* ------------------------------- Makevars.win (try 2: try to find something in lib) ------------------------------- ## Use the R_HOME indirection to support installations of multiple R version ## PKG_CXXFLAGS = `$(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()"` PKG_CPPFLAGS = -I${BOOSTLIB} PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()") `ls ${BOOSTLIB}/lib/*` ------------------------------- Makevars.win (try 3: try to find something in libs) ------------------------------- ## Use the R_HOME indirection to support installations of multiple R version ## PKG_CXXFLAGS = `$(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()"` PKG_CPPFLAGS = -I${BOOSTLIB} PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()") `ls ${BOOSTLIB}/libs/*` ------------------------------- Makevars.win (try 4: try to figure out what are in ${BOOSTLIB}) ------------------------------- ## Use the R_HOME indirection to support installations of multiple R version ## PKG_CXXFLAGS = `$(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()"` PKG_CPPFLAGS = -I${BOOSTLIB} PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()") `ls ${BOOSTLIB}/*` [[alternative HTML version deleted]]
Dirk Eddelbuettel
2013-Nov-03 13:54 UTC
[Rd] How to make an R package that uses Boost.Thread, qualified to be published on CRAN or shared by the most
On 3 November 2013 at 11:35, Simon wrote: | Hi, | | Recently, I made an R package that used the C++ library Boost.Thread (http://www.boost.org/doc/libs/1_54_0/doc/html/thread.html) for multithreading. Previously, I have posted a question at stackoverflow (http://stackoverflow.com/questions/19651954/is-it-possible-to-build-an-r-package-which-use-rcpp-and-boost-thread-on-http), and I also asked at rcpp-devel (http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-November/006777.html). Dirk Eddelbuettel suggested me ask here. After some tries on win-builder and some research on CRAN, there are still some doubts: Thanks for posting here, and for including code. I tried to answer both your questions before. You are now providing more and more context which helps. | 1) For my package to be accepted by CRAN, I am not so sure if it is acceptable to let users to install Boost library themselves? If not, are there any solutions? I found there are some third party external software or libraries used by other R packages, such as OpenMP and gtk, some of which have corresponding R packages, but there are little discuss about Boost. | | (I now know there are some other ways to host my package, but I think CRAN is more straight forward, though it may be stricter.) This question is really several questions: 1a) If I write a package using library xyz, do users need xyz to compile my package? Yes of course. 1b) If I write a package using library xyz, do _windows_ users need xyz to _use_ my package? No as CRAN provides Windows binary packages. 1c) What about the other OSs? It depends. If users need to compile first, then yes. But Boost is very standard on OS X and Linux. So yes, it is quite acceptable to depend on Boost. | 2) As I said in my question at stackoverflow (http://stackoverflow.com/questions/19651954/is-it-possible-to-build-an-r-package-which-use-rcpp-and-boost-thread-on-http), I have tried MAKE variable BOOSTLIB on win-builder (http://win-builder.r-project.org/), It is OK for header-only Boost libraries. I am not sure whether it is OK for separately-compiled libraries such as Boost.Thread, after many fails. Is it possible? Are there any special variables or path for Boost.Thread? May I suppose that it is acceptable for 1) if there are, or at least for header-only Boost libraies? I do not know if BOOSTLIB on win-builder and CRAN also points to a library you can use. And I cannot think of a package using it. Maybe Uwe Ligges will be able to help you here. | (There are an R package called BH provides header-only Boost libraries, but BOOSTLIB make me imagine something else.) BOOSTLIB predates the creation of our BH package by several years. Dirk | | | | Simon | | | | PS: | Below are the source files and results of my tries for exploring BOOSTLIB on win-builder, please forgive me use win-builder as a test machine, so I post my questions here. | The test package is derived from command Rscript -e "Rcpp.package.skeleton()", below just lists some modifications by me. | The outputs in 00install.out are too long to be pasted here. | ------------------------------- | rcpp_hello_world.cpp | ------------------------------- | #include "rcpp_hello_world.h" | | #include "boost/lambda/lambda.hpp" | #include <iostream> | #include <iterator> | #include <algorithm> | #include <vector> | | #include "boost/thread.hpp" | | void wait(int seconds) { | boost::this_thread::sleep(boost::posix_time::seconds(seconds)); | } | | void thread() { | for (int i = 0; i < 5; i++) { | wait(1); | std::cout << i << std::endl; | } | } | | SEXP rcpp_hello_world(){ | using namespace Rcpp ; | using namespace boost::lambda; | | std::vector<int> a; | a.push_back(1); | a.push_back(2); | // std::for_each( a.begin(), a.end(), _1 = 1); | | boost::thread t(thread); | t.join(); | | return wrap(a); | } | | ------------------------------- | Makevars.win (try 1: try to find if there is a file called libboost_thread*) | ------------------------------- | ## Use the R_HOME indirection to support installations of multiple R version | ## PKG_CXXFLAGS = `$(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()"` | PKG_CPPFLAGS = -I${BOOSTLIB} | PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()") ${BOOSTLIB}/lib/libboost_thread* | | ------------------------------- | Makevars.win (try 2: try to find something in lib) | ------------------------------- | ## Use the R_HOME indirection to support installations of multiple R version | ## PKG_CXXFLAGS = `$(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()"` | PKG_CPPFLAGS = -I${BOOSTLIB} | PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()") `ls ${BOOSTLIB}/lib/*` | | ------------------------------- | Makevars.win (try 3: try to find something in libs) | ------------------------------- | ## Use the R_HOME indirection to support installations of multiple R version | ## PKG_CXXFLAGS = `$(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()"` | PKG_CPPFLAGS = -I${BOOSTLIB} | PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()") `ls ${BOOSTLIB}/libs/*` | | ------------------------------- | Makevars.win (try 4: try to figure out what are in ${BOOSTLIB}) | ------------------------------- | ## Use the R_HOME indirection to support installations of multiple R version | ## PKG_CXXFLAGS = `$(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()"` | PKG_CPPFLAGS = -I${BOOSTLIB} | PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()") `ls ${BOOSTLIB}/*` | | | | [[alternative HTML version deleted]] | | ______________________________________________ | R-devel at r-project.org mailing list | https://stat.ethz.ch/mailman/listinfo/r-devel -- Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com