Rcpp映射返回

Rcpp map return

本文关键字:返回 映射 Rcpp      更新时间:2023-10-16

我正试图返回一个从c++到r的映射。我在c++中的代码如下(如https://github.com/RcppCore/Rcpp/blob/master/inst/tinytest/cpp/wrap.cpp):

#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
IntegerVector map_string_int(){
    std::map< std::string, int > m ;
     m["b"] = 100;
    m["a"] = 200;
    m["c"] = 300;
    return wrap(m);
}

我的r代码如下:

require(Rcpp)
Rcpp::sourceCpp(test.cpp')
map_string_int()

尽管代码编译时没有任何错误,但当我调用该函数时,我的r会话会立即终止。有什么想法吗?

[编辑]

R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=Portuguese_Portugal.1252 
[2] LC_CTYPE=Portuguese_Portugal.1252   
[3] LC_MONETARY=Portuguese_Portugal.1252
[4] LC_NUMERIC=C                        
[5] LC_TIME=Portuguese_Portugal.1252    
attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     
other attached packages:
[1] Rcpp_0.11.3
loaded via a namespace (and not attached):
[1] tools_3.1.1

决定尝试另一个编译器,结果成功了!

我已安装Rtools编译器(http://cran.r-project.org/bin/windows/Rtools/)之后,仅更改系统路径以指向Rtools安装文件夹中的bin文件夹。