我正在尝试使用mypackage5
安装RcppEigen.package.skeleton()
软件包,而LogicalVector&
和Rcpp::List getPIcvalue
函数中的RcppExport 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'
1,我尝试将
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)'
2,我尝试将
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属性中存在错误。