如何让Rcpp和BH(Boost标头)与regex_replace for Windows build一起使用

时间:2015-03-26 11:58:09

标签: r boost rcpp

我使用优秀的Rcpp项目在R中实现一些更快的文本处理,但无法在Windows下正确构建包。 (它在OS X和Linux下构建得很好。)我正在使用Rcpp和BH头包。我可以在http://gallery.rcpp.org/articles/boost-regular-expressions/获得示例,我可以获得以下代码,以构建除Windows之外的所有平台。

为了解决我的问题,我将其从较大的包中删除,然后将其放入一个简单的包中,以便可以使用devtools::install_github("kbenoit/boostTest")进行安装。

文件是:

Makevars.win

PKG_LIBS = -lboost_regex

src/clean.cpp

#include <Rcpp.h>
#include <string>
#include <boost/regex.hpp>

// [[Rcpp::depends(BH)]]

const boost::regex re_digits("[[:digit:]]");
const boost::regex re_punct("[[:punct:]]");
const std::string space0("");

std::string removeDigits(const std::string& s) {
    return boost::regex_replace(s, re_digits, space0, boost::match_default | boost::format_sed);
}

std::string removePunct(const std::string& s) {
    return boost::regex_replace(s, re_punct, space0, boost::match_default | boost::format_sed);
}


// [[Rcpp::export]]
Rcpp::DataFrame cleanCpp(std::vector<std::string> str) {
    int n = str.size();
    for (int i=0; i<n; i++) {
        str[i] = removeDigits(str[i]);
        str[i] = removePunct(str[i]);
    }
    return Rcpp::DataFrame::create (Rcpp::Named("text") = str);
}

cleanC.R导出为:

cleanC <- function(x) as.character(cleanCpp(x)[, 1])

(我之所以这样做是因为我对Rcpp很新,我无法弄清楚如何返回一个CharacterVector,但是可以按照上面链接的boost-regular-expressions示例来获取Rcpp :: DataFrame返回类型。< / p>

在我的DESCRIPTION文件中,我有:

LinkingTo: Rcpp,BH

问题在于,当我使用devtools::build_win()构建软件包时,它会失败,即使它在Linux和OS X上构建良好。输出可以在这里看到:

* installing *source* package 'boostTest' ...
** libs

*** arch - i386
g++  -I"D:/RCompile/recent/R-3.1.3/include"            -I"d:/RCompile/CRANpkg/lib/3.1/Rcpp/include" -I"d:/RCompile/CRANpkg/lib/3.1/RcppArmadillo/include" -I"d:/RCompile/CRANpkg/lib/3.1/BH/include" -I"d:/RCompile/r-compiling/local/local320/include"     -O3 -Wall  -mtune=core2            -c RcppExports.cpp -o RcppExports.o
g++  -I"D:/RCompile/recent/R-3.1.3/include"            -I"d:/RCompile/CRANpkg/lib/3.1/Rcpp/include" -I"d:/RCompile/CRANpkg/lib/3.1/RcppArmadillo/include" -I"d:/RCompile/CRANpkg/lib/3.1/BH/include" -I"d:/RCompile/r-compiling/local/local320/include"     -O3 -Wall  -mtune=core2            -c clean.cpp -o clean.o
g++ -shared -s -static-libgcc -o boostTest.dll tmp.def RcppExports.o clean.o -lboost_regex -Ld:/RCompile/r-compiling/local/local320/lib/i386 -Ld:/RCompile/r-compiling/local/local320/lib -LD:/RCompile/recent/R-3.1.3/bin/i386 -lR
d:/compiler/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lboost_regex
collect2: ld returned 1 exit status
no DLL was created
ERROR: compilation failed for package 'boostTest'
* removing 'd:/RCompile/CRANguest/R-release/lib/boostTest'

任何帮助表示赞赏!

0 个答案:

没有答案