R BH package not showing "asio" directory - r

After installing BH package, including following in .cpp file:
#include <Rcpp.h>
#include <boost/asio/ip/address_v4.hpp>
sourcing the cpp file with sourceCpp(".cpp file") is giving :
fatal error: boost/asio/ip/address_v4.hpp: No such file or directory compilation terminated.
In BH/boost directory there is no asio directory.

We never said Boost Asio was part of BH. Quoting from the DESCRIPTION with my highlighting in italics below:
Description: Boost provides free peer-reviewed portable C++ source
libraries. A large part of Boost is provided as C++ template code
which is resolved entirely at compile-time without linking. This
package aims to provide the most useful subset of Boost libraries
for template use among CRAN package. By placing these libraries in
this package, we offer a more efficient distribution system for CRAN
as replication of this code in the sources of other packages is
avoided.
Asio, thread, ... and a few others require linking and can never be part of BH.

Related

Makevars cannot find libguile.h but the file exists [duplicate]

I have some C++ code that I intend to export into my r package using Rcpp. However, this code links to fftw3 via
#include <fftw3.h>
at the top of the file. When I try to compile this code, I unsurprisingly get the error
fatal error: 'fftw3.h' file not found
What is the proper way to link to this file so that it will be available upon compilation of my package? I know that a Makevars file can generally be used to link to system libraries but since this library is external I'm not sure what to do.
Thanks,
Eric.
Please see the Rcpp vignette Rcpp libraries -- which is also this arXiv paper.
There are many examples among the 2400+ CRAN packages using Rcpp. My hunch would probably be to look at what I contributed to the nloptr package -- even though that is a more complicated scheme where we allow use either a system library if present (could be the case with fftw3 too) or downloand and build.
Rcpp has been used a lot to build such glue. The most common, and simplest , approach is to look for pkg-config and query it for headers and libraries. Please give that a shot (with some looking around CRAN or GitHub for examples).
Edit: There is also an (old) fftw3 package by Gabor at his previous employer's GitHub org as well as another CRAN package fftwtools (which, if memory served, I helped once too but I don't recall now what for).

Linking to fftw3.h in C++ source file for R package

I have some C++ code that I intend to export into my r package using Rcpp. However, this code links to fftw3 via
#include <fftw3.h>
at the top of the file. When I try to compile this code, I unsurprisingly get the error
fatal error: 'fftw3.h' file not found
What is the proper way to link to this file so that it will be available upon compilation of my package? I know that a Makevars file can generally be used to link to system libraries but since this library is external I'm not sure what to do.
Thanks,
Eric.
Please see the Rcpp vignette Rcpp libraries -- which is also this arXiv paper.
There are many examples among the 2400+ CRAN packages using Rcpp. My hunch would probably be to look at what I contributed to the nloptr package -- even though that is a more complicated scheme where we allow use either a system library if present (could be the case with fftw3 too) or downloand and build.
Rcpp has been used a lot to build such glue. The most common, and simplest , approach is to look for pkg-config and query it for headers and libraries. Please give that a shot (with some looking around CRAN or GitHub for examples).
Edit: There is also an (old) fftw3 package by Gabor at his previous employer's GitHub org as well as another CRAN package fftwtools (which, if memory served, I helped once too but I don't recall now what for).

R package `libs` directory too large after compilation to submit on CRAN

I am the developer of the following package https://gitlab.inria.fr/gdurif/pCMF and I have a problem: the compiled library is too big.
When I check it with R CMD check, I get the following note regarding the size of the compiled library:
checking installed package size ... NOTE installed size is 31.0Mb sub-directories of 1Mb or more:
libs 30.8Mb
My package is based on C++ code interfaced thanks to the package rcpp and heavily uses the algebra template library Eigen based on the package RcppEigen.
Since Eigen is templated, I think that the compiled library can become large. However, I would like to submit my package on the CRAN and I have no idea at all how I could solve this.
Thanks

Develop R package for different platform

I develope a package using Rcpp, cpp include "windows.h" library, but this package is not available on Linux, so I decided to achieve the same function using reticulate package to call python package, how should I make package detect installed on which platform ?
If on Windows platform, installing my package will compile cpp file , if on Linux , installing my package will not compile cpp file but using my r code inside.
For example:
Windows:
myfunction<-function(){
.Call(C++ function)
}
And also avoid compile cpp file in src folder or there will be error : "no windows.h library"
Linux:
myfunction<-function(){
library(reticulate)
import(py_package)
}
Maybe you can rethink your approach and provide a C++ solution on platforms other than Windows too? But in short you can the following:
In R
Use eg if (Sys.info()[["sysname"]] == "Windows") to test for windows, and in the else branch call the replacement
In C/C++
Use #define tests such as #if defined(_WIN32) to bracket the #include <windows>, and also the body of your function. Just return eg nothing on other platforms.
Many packages do things depending on the platform they are on. Feel free to look around at existing sources -- CRAN has over 12k and GitHub is treasure trove too.

How to define a Rcpp package based on several different cpp files?

I have define several .cpp files.
One of them needs the package RcppArmadillo;
The others need the package Rcpp.
After my Rcpp package is generated and when i install it, I compile several errors as follows:
RcppExports.cpp:49: error: ‘arma’ has not been declared
RcppExports.cpp:49: error: ‘arma’ has not been declared
RcppExports.cpp:49: error: expected `;' before ‘__result’
RcppExports.cpp:50: error: ‘__result’ was not declared in this scope
make: *** [RcppExports.o] Error 1
When I check RcppExports.cpp file in src, the include head is like this:
#include <Rcpp.h>
What should I do? How to handle this problem? Thank you very much!
This is extensively documented, and there are thirty CRAN packages using RcppArmadillo you could look at for working examples and guidance.
Start with
RcppArmadillo.package.skeleton()
to create an (almost empty) working package for RcppArmadillo, then drop your files in the src/ directory of that package.
The RcppArmadillo.package.skeleton() has options, so consider reading its help page. The Rcpp package has a lot of documentation you may want to look at too, including one entire vignette about package building.

Resources