My C++ code is to take in a character vector and converting it into a std::set. The following code compiles on Mac but not on Linux:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::export]]
void test(CharacterVector x) {
std::set<std::string> vs(x.begin(), x.end());
}
Linux compilation fails with:
/usr/include/c++/4.8.2/bits/stl_function.h:481:7: note: no known conversion for argument 1 from ‘Rcpp::internal::string_proxy<16>’ to ‘const std::basic_string<char>&’
Mac info:
R version 3.4.1 (2017-06-30) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS High Sierra 10.13.3 Rcpp_0.12.16
Linux info:
R version 3.4.2 (2017-09-28) Platform: x86_64-redhat-linux-gnu (64-bit) Running under: CentOS Linux 7 (Core) Rcpp_0.12.16
As a workaround, I can first convert the character vector to std::vector, and then the std::vector to std::set. However, this incurs a ~5-10% performance penalty in my tests which I'd like to avoid.
Is this a bug? How do I do it properly on linux?
This variant works with g++ 7.2 on Ubuntu 17.10:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::export]]
void test(std::vector<std::string> x) {
std::set<std::string> vs(x.begin(), x.end());
}
and runs (but does nothing)
R> Rcpp::sourceCpp("/tmp/soQ.cpp")
R> test(rep("lalala", 3))
R>
Character vectors are complicated; there is possibly something less than ideal going on with the iterators. Careful PRs are welcome; in the meantime you have an easy alternative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With