I am developing an R package containing C++ code, and I would like to use the standard library header "execution". As C++17 is the default on CRAN now, this seems to be fine. However, this header is not yet implemented in Apple Clang, and from what I can tell from the R for macOS Developer website, C++ code in R packages on macOS will be compiled using Apple's toolchain.
Hence, my question is: Let's say I have a function similar to the one below, computing the set difference in parallel. Would this cause the package build to fail for macOS on CRAN?
#include <RcppArmadillo.h>
#include <execution>
using namespace arma;
// [[Rcpp::export]]
vec setdiff(const vec& x, const vec& y) {
vec xs = sort(x);
vec ys = sort(y);
std::vector<double> diff;
std::set_difference(
std::execution::par,
xs.begin(), xs.end(), ys.begin(), ys.end(),
std::inserter(diff, diff.begin()));
return conv_to<vec>::from(diff);
}
/*** R
setdiff(1:10, 3)
*/
On my own M1 Mac, I can make this compile by adding the following lines to ~/.R/Makevars, thus making sure I use g++ and not Apply clang.
CXX=/opt/homebrew/bin/g++-13
CXX17=/opt/homebrew/bin/g++-13
I tried something similar to what @SymbolixAU suggested in a comment.
I created a package named
anRpackagewith the following files:DESCRIPTIONsrc/setdiff.cppsrc/Makevarsandsrc/Makevars.winRdirectory containing the auto-generatedRcppExports.R.Submitting to win-builder,
devtools::check_win_devel(), it succeeded. Instead submitting to R Mac Builder, the build failed.