Hello,
I know this question has been answered before (and I have searched for it), but I cannot figure out a solution:
I want to use boost with Rcpp, basically to be able to use numbers with a higher precision than a double. I am comfortable using the inline package for small c++ functions, I have never used Rccp per se. I have created a skeleton with convolve, and it works. I have added a new function:
// We can now use the BH package// [[Rcpp::depends(BH)]]
#include <Rcpp.h>#include <boost/math/common_factor.hpp>
using namespace Rcpp; // [[Rcpp::export]]int computeGCD(int a, int b) { return boost::math::gcd(a, b);}
and when I try to compile, it fails (basically, the compiler does not find where boost is). I have then run in R:
Sys.setenv("PKG_CXXFLAGS"="-I C:/Program~Files/boost/boost_1_57_0/")
which allows me to go a bit more into the build, but the compile fails when reaching the #include <boost/math/common_factor.hpp> above, since it does not know where boost is (boost is at C:/Program~Files/boost/boost_1_57_0/ I have not compiled it, but just extracted with 7-zip and copied and pasted the corresponding files into this subfolder).
From reading the attribute document of Dirk Eddelbuettel, it seems as if adding the comments // [[Rcpp::export]] and // [[Rcpp::depends(BH)]] would do the job. But for me, it does not work. What do I need to do? Thanks and sorry for the basic question, I have tried to read everything I could before asking this list.
I think you want to check your DESCRIPTION file. I believe you need to
have the 'LinkingTo:' option to also include BH.
Regards,
Charles
On Wed, Mar 11, 2015 at 6:58 AM, Jordi Molins Coronado <
jordi_molins at hotmail.com> wrote:
Hello,
I know this question has been answered before (and I have searched for
it), but I cannot figure out a solution:
I want to use boost with Rcpp, basically to be able to use numbers with a
higher precision than a double. I am comfortable using the inline package
for small c++ functions, I have never used Rccp per se. I have created a
skeleton with convolve, and it works. I have added a new function:
// We can now use the BH package
// [[Rcpp::depends(BH)]]
#include <Rcpp.h>
#include <boost/math/common_factor.hpp>
using namespace Rcpp;
// [[Rcpp::export]]
int computeGCD(int a, int b) {
return boost::math::gcd(a, b);
}
and when I try to compile, it fails (basically, the compiler does not find
where boost is). I have then run in R:
Sys.setenv("PKG_CXXFLAGS"="-I C:/Program~Files/boost/boost_1_57_0/")
which allows me to go a bit more into the build, but the compile fails
when reaching the #include <boost/math/common_factor.hpp> above, since
it does not know where boost is (boost is at C:/Program~Files/boost/boost_1_57_0/
I have not compiled it, but just extracted with 7-zip and copied and pasted
the corresponding files into this subfolder).
From reading the attribute document of Dirk Eddelbuettel, it seems as if
adding the comments // [[Rcpp::export]] and // [[Rcpp::depends(BH)]]
would do the job. But for me, it does not work. What do I need to do?
Thanks and sorry for the basic question, I have tried to read everything I
could before asking this list.
Thank you very much for your answer. I have changed the DESCRIPTION file to include:
LinkingTo: Rcpp, BH
(before: LinkingTo: Rcpp) but it continues giving the same build error.
Date: Wed, 11 Mar 2015 07:05:39 -0500
Subject: Re: [Rcpp-devel] Question about Rcpp and boost
From: deter088 at umn.edu
To: jordi_molins at hotmail.com
CC: rcpp-devel at lists.r-forge.r-project.org
I think you want to check your DESCRIPTION file. I believe you need to have the 'LinkingTo:' option to also include BH.
Regards,Charles
On Wed, Mar 11, 2015 at 6:58 AM, Jordi Molins Coronado <jordi_molins at hotmail.com> wrote:
Hello,
I know this question has been answered before (and I have searched for it), but I cannot figure out a solution:
I want to use boost with Rcpp, basically to be able to use numbers with a higher precision than a double. I am comfortable using the inline package for small c++ functions, I have never used Rccp per se. I have created a skeleton with convolve, and it works. I have added a new function:
// We can now use the BH package// [[Rcpp::depends(BH)]]
#include <Rcpp.h>#include <boost/math/common_factor.hpp>
using namespace Rcpp; // [[Rcpp::export]]int computeGCD(int a, int b) { return boost::math::gcd(a, b);}
and when I try to compile, it fails (basically, the compiler does not find where boost is). I have then run in R:
Sys.setenv("PKG_CXXFLAGS"="-I C:/Program~Files/boost/boost_1_57_0/")
which allows me to go a bit more into the build, but the compile fails when reaching the #include <boost/math/common_factor.hpp> above, since it does not know where boost is (boost is at C:/Program~Files/boost/boost_1_57_0/ I have not compiled it, but just extracted with 7-zip and copied and pasted the corresponding files into this subfolder).
From reading the attribute document of Dirk Eddelbuettel, it seems as if adding the comments // [[Rcpp::export]] and // [[Rcpp::depends(BH)]] would do the job. But for me, it does not work. What do I need to do? Thanks and sorry for the basic question, I have tried to read everything I could before asking this list.
On 11 March 2015 at 07:05, Charles Determan Jr wrote:
| I think you want to check your DESCRIPTION file.? I believe you need to have
| the 'LinkingTo:' option to also include BH.
Beat me to it :)
That is exactly it -- "LinkingTo: BH" is what you need (and our documentation
says so in many places).
Also look at eg the CRAN page for BH and the list of reverse dependencies and
pick a (small) package also using Rcpp -- for example my RcppAnnoy. Download
its source and study its package structure as this is _exactly_ the framework
you want to copy.
Use the copious examples out there to your advantage.
Dirk
Could you provide the build error you are referring to? You shouldn't need
to change the PKG_CXXFLAGS variable at all. Try restarting your
environment and rebuilding. I just created a package containing your code
with the BH package without error on Windows 7.
On Wed, Mar 11, 2015 at 7:09 AM, Jordi Molins Coronado <
jordi_molins at hotmail.com> wrote:
Thank you very much for your answer. I have changed the DESCRIPTION file
to include:
LinkingTo: Rcpp, BH
(before: LinkingTo: Rcpp) but it continues giving the same build error.
------------------------------
Date: Wed, 11 Mar 2015 07:05:39 -0500
Subject: Re: [Rcpp-devel] Question about Rcpp and boost
From: deter088 at umn.edu
To: jordi_molins at hotmail.com
CC: rcpp-devel at lists.r-forge.r-project.org
I think you want to check your DESCRIPTION file. I believe you need to
have the 'LinkingTo:' option to also include BH.
Regards,
Charles
On Wed, Mar 11, 2015 at 6:58 AM, Jordi Molins Coronado <
jordi_molins at hotmail.com> wrote:
Hello,
I know this question has been answered before (and I have searched for
it), but I cannot figure out a solution:
I want to use boost with Rcpp, basically to be able to use numbers with a
higher precision than a double. I am comfortable using the inline package
for small c++ functions, I have never used Rccp per se. I have created a
skeleton with convolve, and it works. I have added a new function:
// We can now use the BH package
// [[Rcpp::depends(BH)]]
#include <Rcpp.h>
#include <boost/math/common_factor.hpp>
using namespace Rcpp;
// [[Rcpp::export]]
int computeGCD(int a, int b) {
return boost::math::gcd(a, b);
}
and when I try to compile, it fails (basically, the compiler does not find
where boost is). I have then run in R:
Sys.setenv("PKG_CXXFLAGS"="-I C:/Program~Files/boost/boost_1_57_0/")
which allows me to go a bit more into the build, but the compile fails
when reaching the #include <boost/math/common_factor.hpp> above, since
it does not know where boost is (boost is at C:/Program~Files/boost/boost_1_57_0/
I have not compiled it, but just extracted with 7-zip and copied and pasted
the corresponding files into this subfolder).
From reading the attribute document of Dirk Eddelbuettel, it seems as if
adding the comments // [[Rcpp::export]] and // [[Rcpp::depends(BH)]]
would do the job. But for me, it does not work. What do I need to do?
Thanks and sorry for the basic question, I have tried to read everything I
could before asking this list.
I have restarted everything, and now I can already compute GCD using the boost library, thank you for your help. Just an annoying thing: when I do:
sourceCpp("convolve.cpp")
I get a warning, which I did not get the first time I built my project (without the boost file).
Warning message:In normalizePath(path.expand(path), winslash, mustWork) : path[1]="C:/Users/Jordi/Documents/[A_FOLDER]/JungleR/JungleR/src/../inst/include": The system cannot find the path specified
Do you know what can that be? I will definitely look into the examples in BH library, thanks for the recommendation.
Date: Wed, 11 Mar 2015 07:21:49 -0500
Subject: Re: [Rcpp-devel] Question about Rcpp and boost
From: deter088 at umn.edu
To: jordi_molins at hotmail.com
CC: rcpp-devel at lists.r-forge.r-project.org
Could you provide the build error you are referring to? You shouldn't need to change the PKG_CXXFLAGS variable at all. Try restarting your environment and rebuilding. I just created a package containing your code with the BH package without error on Windows 7.
On Wed, Mar 11, 2015 at 7:09 AM, Jordi Molins Coronado <jordi_molins at hotmail.com> wrote:
Thank you very much for your answer. I have changed the DESCRIPTION file to include:
LinkingTo: Rcpp, BH
(before: LinkingTo: Rcpp) but it continues giving the same build error.
Date: Wed, 11 Mar 2015 07:05:39 -0500
Subject: Re: [Rcpp-devel] Question about Rcpp and boost
From: deter088 at umn.edu
To: jordi_molins at hotmail.com
CC: rcpp-devel at lists.r-forge.r-project.org
I think you want to check your DESCRIPTION file. I believe you need to have the 'LinkingTo:' option to also include BH.
Regards,Charles
On Wed, Mar 11, 2015 at 6:58 AM, Jordi Molins Coronado <jordi_molins at hotmail.com> wrote:
Hello,
I know this question has been answered before (and I have searched for it), but I cannot figure out a solution:
I want to use boost with Rcpp, basically to be able to use numbers with a higher precision than a double. I am comfortable using the inline package for small c++ functions, I have never used Rccp per se. I have created a skeleton with convolve, and it works. I have added a new function:
// We can now use the BH package// [[Rcpp::depends(BH)]]
#include <Rcpp.h>#include <boost/math/common_factor.hpp>
using namespace Rcpp; // [[Rcpp::export]]int computeGCD(int a, int b) { return boost::math::gcd(a, b);}
and when I try to compile, it fails (basically, the compiler does not find where boost is). I have then run in R:
Sys.setenv("PKG_CXXFLAGS"="-I C:/Program~Files/boost/boost_1_57_0/")
which allows me to go a bit more into the build, but the compile fails when reaching the #include <boost/math/common_factor.hpp> above, since it does not know where boost is (boost is at C:/Program~Files/boost/boost_1_57_0/ I have not compiled it, but just extracted with 7-zip and copied and pasted the corresponding files into this subfolder).
From reading the attribute document of Dirk Eddelbuettel, it seems as if adding the comments // [[Rcpp::export]] and // [[Rcpp::depends(BH)]] would do the job. But for me, it does not work. What do I need to do? Thanks and sorry for the basic question, I have tried to read everything I could before asking this list.
Jordi,
1) Please edit your replies. There is no need to return all the prior emails.
2) Please read the vignette 'Rcpp Attributes'. The vignette has all the
answers. In short you REALLY do not want sourceCpp in a package.
Dirk
I have an odd problem: now I have the computeGCD function working. My next step has been to create another function doing something trivial, but adding the include for multiprecision of integers:
// We can now use the BH package// [[Rcpp::depends(BH)]]
#include <Rcpp.h>#include <boost/multiprecision/cpp_int.hpp>#include <boost/math/common_factor.hpp>
using namespace Rcpp;
// [[Rcpp::export]]int precision(int num) { int fact = 1; for(int i=num; i>1; --i) { fact *= i; } return fact*boost::math::gcd(8, 16);
The build does not work, and the error message is:
precisionboost.cpp:5:44: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directorycompilation terminated.
This is odd, since if I delete the corresponding include for multiprecision and I leave the one of math, the compilation ends without problems. So, it cannot be a LinkingTo issue. Of course, the file cpp_int.hpp is there.
I have tried to find references to the use of boost multiprecision within Rcpp, but I have not found any.
Any idea of what is going on?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150311/53797435/attachment.html>
I think I can answer my own question: #include <boost/multiprecision/cpp_int.hpp> is not in the BH package. Instead, #include <boost/multiprecision/cpp_dec_float.hpp> is included, so if I add this #include in my file, the compile works. But apparently, I cannot include cpp_int.cpp.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150311/627025ca/attachment.html>
On 11 March 2015 at 19:34, Jordi Molins Coronado wrote:
| I think I can answer my own question: #include <boost/multiprecision/
| cpp_int.hpp> is not in the BH package. Instead, #include <boost/multiprecision/
| cpp_dec_float.hpp> is included, so if I add this #include in my file, the
| compile works. But apparently, I cannot include cpp_int.cpp.
Correct, it is not (yet) in BH.
But I just filed an issue for BH to include multiprecision next time I update
the package.
Dirk