[Rcpp-devel] How to efficiently remove some words from a big vector of strings.

Dirk Eddelbuettel edd at debian.org
Sun Dec 22 15:14:22 CET 2013


On 22 December 2013 at 14:46, contact AG STUDY wrote:
| I am trying to write an efficient c++ function to remove some words from a big
| vector of strings.
| Here my code using stl :
| 
| vector<std::string> stripWords(vector<std::string>& input, 
|                   std::set<std::string>& toRemove){ 
| input.erase(
|      remove_if(input.begin(), input.end(), 
|                  [&toRemove](const std::string& x) -> bool {
|                      return toRemove.find(x) != toRemove.end();
|                  }),input.end());
| }
| 
| But I get this warning about using lambda expression and this template error.
| 
| 
|  warning: lambda expressions only available with -std=c++0x or -std=gnu++0x
| [enabled by default]

R is (by default) not configured to use C++11. We are slowly moving towards
getting that changed (ie see NEWS in the R-devel sources).

For the time being you can either

 i)   for all R sessions, set the required option as an argument to CXXFLAGS in
      ~/.R/Makevars, or its system-wide equivalent, or another script where
      you set environment variables

 ii)  if you use Rcpp Attributes, use `[[Rcpp::plugins(cpp11)]]` and see
      `help(pluginsAttribute)`  for details

 iii) for a package use src/Makevars or src/Makevars.win
 
|  error: no matching function for call to 'remove_if(std::vector
| <std::basic_string<char> >::iterator, std::vector<std::basic_string<char>
| >::iterator, stripWords(std::vector<std::basic_string<char> >&, std::set
| <std::basic_string<char> >&)::<lambda(const string&)>)'

Try prefixing it with  std::  as you did with the things from the std
namespace. 

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list