c++ - 如何使用 boolean 数组或 LogicalVector Rcpp::List getPIcvalue() 和 RcppExport SEXP mypackage5_getPIcvalue()

标签 c++ arrays r boolean rcpp

我正在尝试使用 RcppEigen.package.skeleton() 安装 mypackage5 包,但是 中的 LogicalVector& 有问题>Rcpp::List getPIcvalueRcppExport SEXP mypackage5_getPIcvalue 函数。这是带有 bool varIn[] 的 C++ 函数,

#include <RcppEigen.h>
#include <Rcpp.h>
using namespace Eigen;
using namespace Rcpp;
using std::string;

// getPIcvalue
Rcpp::List getPIcvalue(int p, bool nest, string criteria, bool varIn[], bool findIn, int n,const MatrixXd& Y,const MatrixXd& Xf,const MatrixXd& X0,double sigma);
RcppExport SEXP mypackage5_getPIcvalue(SEXP pSEXP,SEXP nestSEXP,SEXP criSEXP,SEXP varInSEXP,SEXP findInSEXP,SEXP nSEXP,SEXP YSEXP,SEXP XfSEXP,SEXP X0SEXP,SEXP sigmaSEXP) {
BEGIN_RCPP
    SEXP __sexp_result;
    {
        Rcpp::RNGScope __rngScope;
        Rcpp::traits::input_parameter< int >::type p(pSEXP );
        Rcpp::traits::input_parameter< bool >::type nest(nestSEXP );
        Rcpp::traits::input_parameter< string >::type criteria(criSEXP );
        Rcpp::traits::input_parameter< bool >::type varIn[](varInSEXP );
        Rcpp::traits::input_parameter< bool >::type findIn(findInSEXP );
        Rcpp::traits::input_parameter< int >::type n(nSEXP );
        Rcpp::traits::input_parameter< const MatrixXd& >::type Y(YSEXP );
        Rcpp::traits::input_parameter< const MatrixXd& >::type Xf(XfSEXP );
        Rcpp::traits::input_parameter< const MatrixXd& >::type X0(X0SEXP );
        Rcpp::traits::input_parameter< double >::type sigma(sigmaSEXP );
        Rcpp::List __result = getPIcvalue(p, nest, criteria, varIn[], findIn, n, Y, Xf, X0, sigma);
        PROTECT(__sexp_result = Rcpp::wrap(__result));
    }
    UNPROTECT(1);
    return __sexp_result;
END_RCPP
}

当我运行 Rcmd INSTALL --build mypackage5 时,错误是:

* installing *source* package 'mypackage5' ...
** libs

*** arch - i386
cygwin warning:
  MS-DOS style path detected: C:/R/R-31~1.1/etc/i386/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/R/R-31~1.1/etc/i386/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
g++ -m32 -I"C:/R/R-31~1.1/include" -DNDEBUG    -I"C:/Users/LJH/Documents/R/win-library/3.1/Rcpp/include" -I"C:/Users/LJH/Documents/R/win-library/3.1/RcppEigen/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp: In function 'SEXPREC* mypackage5_getPIcvalue(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)':
RcppExports.cpp:27:68: error: expected primary-expression before ']' token
make: *** [RcppExports.o] Error 1
Warning: running command 'make -f "Makevars.win" -f "C:/R/R-31~1.1/etc/i386/Makeconf" -f "C:/R/R-31~1.1/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="mypackage5.dll" OBJECTS="RcppExports.o rcppeigen_hello_world.o"' had status 2
cygwin warning:
  MS-DOS style path detected: C:/R/R-31~1.1/etc/i386/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/R/R-31~1.1/etc/i386/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
g++ -m32 -I"C:/R/R-31~1.1/include" -DNDEBUG    -I"C:/Users/LJH/Documents/R/win-library/3.1/Rcpp/include" -I"C:/Users/LJH/Documents/R/win-library/3.1/RcppEigen/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp: In function 'SEXPREC* mypackage5_getPIcvalue(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)':
RcppExports.cpp:27:68: error: expected primary-expression before ']' token
make: *** [RcppExports.o] Error 1
Warning: running command 'make -f "Makevars.win" -f "C:/R/R-31~1.1/etc/i386/Makeconf" -f "C:/R/R-31~1.1/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="mypackage5.dll" OBJECTS="RcppExports.o rcppeigen_hello_world.o" symbols.rds' had status 2
ERROR: compilation failed for package 'mypackage5'
* removing 'C:/Users/LJH/Documents/mypackage5.Rcheck/mypackage5'

第一,我尝试将 bool varIn[] 更改为 bool *varIn

// getPIcvalue
Rcpp::List getPIcvalue(int p, bool nest, string criteria, bool *varIn, bool findIn, int n,const MatrixXd& Y,const MatrixXd& Xf,const MatrixXd& X0,double sigma);
RcppExport SEXP mypackage5_getPIcvalue(SEXP pSEXP,SEXP nestSEXP,SEXP criSEXP,SEXP varInSEXP,SEXP findInSEXP,SEXP nSEXP,SEXP YSEXP,SEXP XfSEXP,SEXP X0SEXP,SEXP sigmaSEXP) {
BEGIN_RCPP
    SEXP __sexp_result;
    {
        Rcpp::RNGScope __rngScope;
        Rcpp::traits::input_parameter< int >::type p(pSEXP );
        Rcpp::traits::input_parameter< bool >::type nest(nestSEXP );
        Rcpp::traits::input_parameter< string >::type criteria(criSEXP );
        Rcpp::traits::input_parameter< bool >::type varIn(varInSEXP );
        Rcpp::traits::input_parameter< bool >::type findIn(findInSEXP );
        Rcpp::traits::input_parameter< int >::type n(nSEXP );
        Rcpp::traits::input_parameter< const MatrixXd& >::type Y(YSEXP );
        Rcpp::traits::input_parameter< const MatrixXd& >::type Xf(XfSEXP );
        Rcpp::traits::input_parameter< const MatrixXd& >::type X0(X0SEXP );
        Rcpp::traits::input_parameter< double >::type sigma(sigmaSEXP );
        Rcpp::List __result = getPIcvalue(p, nest, criteria, varIn, findIn, n, Y, Xf, X0, sigma);
        PROTECT(__sexp_result = Rcpp::wrap(__result));
    }
    UNPROTECT(1);
    return __sexp_result;
END_RCPP
}

我遇到了这个错误:

RcppExports.cpp: In function 'SEXPREC* mypackage5_getPIcvalue(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)':
RcppExports.cpp:27:96: error: cannot convert 'Rcpp::traits::input_parameter<bool>::type {aka Rcpp::InputParameter<bool>}' to 'bool*' for argument '4' to 'Rcpp::List getPIcvalue(int, bool, std::string, bool*, bool, int, const MatrixXd&, const MatrixXd&, const MatrixXd&, double)'

第二,我尝试将 bool varIn[] 更改为 LogicalVector& varIn

// getPIcvalue
Rcpp::List getPIcvalue(int p, bool nest, string criteria, LogicalVector& varIn, bool findIn, int n,const MatrixXd& Y,const MatrixXd& Xf,const MatrixXd& X0,double sigma);
RcppExport SEXP mypackage5_getPIcvalue(SEXP pSEXP,SEXP nestSEXP,SEXP criSEXP,SEXP varInSEXP,SEXP findInSEXP,SEXP nSEXP,SEXP YSEXP,SEXP XfSEXP,SEXP X0SEXP,SEXP sigmaSEXP) {
BEGIN_RCPP
    SEXP __sexp_result;
    {
        Rcpp::RNGScope __rngScope;
        Rcpp::traits::input_parameter< int >::type p(pSEXP );
        Rcpp::traits::input_parameter< bool >::type nest(nestSEXP );
        Rcpp::traits::input_parameter< string >::type criteria(criSEXP );
        Rcpp::traits::input_parameter< const LogicalVector& >::type varIn(varInSEXP );
        Rcpp::traits::input_parameter< bool >::type findIn(findInSEXP );
        Rcpp::traits::input_parameter< int >::type n(nSEXP );
        Rcpp::traits::input_parameter< const MatrixXd& >::type Y(YSEXP );
        Rcpp::traits::input_parameter< const MatrixXd& >::type Xf(XfSEXP );
        Rcpp::traits::input_parameter< const MatrixXd& >::type X0(X0SEXP );
        Rcpp::traits::input_parameter< double >::type sigma(sigmaSEXP );
        Rcpp::List __result = getPIcvalue(p, nest, criteria, varIn, findIn, n, Y, Xf, X0, sigma);
        PROTECT(__sexp_result = Rcpp::wrap(__result));
    }
    UNPROTECT(1);
    return __sexp_result;
END_RCPP
}

错误是:

RcppExports.cpp: In function 'SEXPREC* mypackage5_getPIcvalue(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)':
RcppExports.cpp:27:96: error: invalid initialization of reference of type 'Rcpp::LogicalVector& {aka Rcpp::Vector<10, Rcpp::PreserveStorage>&}' from expression of type 'Rcpp::traits::input_parameter<Rcpp::Vector<10, Rcpp::PreserveStorage> >::type {aka Rcpp::InputParameter<Rcpp::Vector<10, Rcpp::PreserveStorage> >}'
RcppExports.cpp:11:12: error: in passing argument 4 of 'Rcpp::List getPIcvalue(int, bool, std::string, Rcpp::LogicalVector&, bool, int, Eigen::MatrixXd&, Eigen::MatrixXd&, Eigen::MatrixXd&, double)'
make: *** [RcppExports.o] Error 1
Warning: running command 'make -f "Makevars.win" -f "C:/R/R-31~1.1/etc/i386/Makeconf" -f "C:/R/R-31~1.1/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="mypackage5.dll" OBJECTS="RcppExports.o rcppeigen_hello_world.o"' had status 2

谁能帮帮我?提前谢谢你。

最佳答案

Rcpp 属性不能处理像bool varIn[] 这样的数组参数,或类似 bool *varIn 的指针.

关于你的尝试 2,你有一些 const getPIcvalue 之间的不匹配这需要 LogicalVector&mypackage5_getPIcvalue由于某种原因使用 Rcpp::traits::input_parameter< const LogicalVector& >::type .

您是否生成了 mypackage5_getPIcvalue手动?如果是,为什么?如果不是,则 Rcpp 属性中存在错误。

关于c++ - 如何使用 boolean 数组或 LogicalVector Rcpp::List getPIcvalue() 和 RcppExport SEXP mypackage5_getPIcvalue(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26738265/

相关文章:

c++ - 解释字符串文字

r - Dplyr:在不均匀因子水平内减去

regex - R:回归匹配特定模式的所有变量

r - 使用 RCurl postForm 收集 JSON 数据

C++ 声明其大小值来自 const 数组的数组

c++ - 可以比较 std::type_info 上的指针是否在常量表达式中相等?

c++ - 使用 ISO C++0x 线程会降低性能

c++ - C++编译错误

c++ - 分配对象数组动态卡住

c - 检查升序数组中有多少个系列的函数的算法是什么。并检测c中最长的系列