Rcpp编译错误:无法将列表转换为SEXP
如果我修改一些正在工作的Rcpp代码以将其放入类中,它将停止工作 以下是工作的、非基于类的代码:Rcpp编译错误:无法将列表转换为SEXP,r,rcpp,R,Rcpp,如果我修改一些正在工作的Rcpp代码以将其放入类中,它将停止工作 以下是工作的、非基于类的代码: #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] List test1_() { Rcpp::NumericVector x = Rcpp::NumericVector::create(1.0); return Rcpp::List::create(Rcpp::Named("x") = x); } #包括
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
List test1_() {
Rcpp::NumericVector x = Rcpp::NumericVector::create(1.0);
return Rcpp::List::create(Rcpp::Named("x") = x);
}
#包括
使用名称空间Rcpp;
//[[Rcpp::导出]]
列表test1_u1;(){
Rcpp::NumericVector x=Rcpp::NumericVector::create(1.0);
返回Rcpp::List::create(Rcpp::Named(“x”)=x);
}
但是当我把它分成.cpp
// testlist.cpp
#include <Rcpp.h>
#include "testlist.h"
using namespace Rcpp;
// [[Rcpp::export]]
SEXP test2_() {
testlist a_testlist;
return a_testlist.test;
}
//testlist.cpp
#包括
#包括“testlist.h”
使用名称空间Rcpp;
//[[Rcpp::导出]]
SEXP测试2_uz(){
测试列表a_测试列表;
返回一个_testlist.test;
}
。。。还有,h
// testlist.h
#ifndef TESTLIST_
#define TESTLIST_
#include <Rcpp.h>
class testlist {
public:
testlist() {}
Rcpp::List test() {
Rcpp::NumericVector x = Rcpp::NumericVector::create(1.0);
return Rcpp::List::create(Rcpp::Named("x") = x);
}
};
#endif
//testlist.h
#ifndef测试列表_
#定义测试列表_
#包括
类测试列表{
公众:
testlist(){}
Rcpp::列表测试(){
Rcpp::NumericVector x=Rcpp::NumericVector::create(1.0);
返回Rcpp::List::create(Rcpp::Named(“x”)=x);
}
};
#恩迪夫
。。。然后我得到以下编译错误
g++ -I/usr/include/R/ -DNDEBUG -D_FORTIFY_SOURCE=2 -I"/home/nacnudus/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include" -fpic -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -c RcppExports.cpp -o RcppExports.o
g++ -I/usr/include/R/ -DNDEBUG -D_FORTIFY_SOURCE=2 -I"/home/nacnudus/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include" -fpic -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -c testlist.cpp -o testlist.o
testlist.cpp: In function ‘Rcpp::List test2_()’:
testlist.cpp:8:21: error: cannot convert ‘testlist::test’ from type ‘Rcpp::List (testlist::)() {aka Rcpp::Vector<19> (testlist::)()}’ to type ‘Rcpp::List {aka Rcpp::Vector<19>}’
return a_testlist.test;
^~~~
make: *** [/usr/lib64/R/etc/Makeconf:141: testlist.o] Error 1
ERROR: compilation failed for package ‘testlist’
* removing ‘/tmp/RtmppNxPq5/devtools_install_f654fb60a32/testlist’
g++-I/usr/include/R/-DNDEBUG-D_FORTIFY_SOURCE=2-I”/home/nacnudus/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include“-fpic-march=x86-64-mtune=generic-O2-pipe-fstack-protector-strong-c RcppExports.cpp-o RcppExports.o
g++-I/usr/include/R/-DNDEBUG-D_-FORTIFY_SOURCE=2-I”/home/nacnudus/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include“-fpic-march=x86-64-mtune=generic-O2-pipe-fstack-protector-strong-c testlist.cpp-o testlist.o
testlist.cpp:在函数“Rcpp::List test2_389;()”中:
testlist.cpp:8:21:错误:无法将“testlist::test”从类型“Rcpp::List(testlist:)(){aka Rcpp::Vector(testlist:)()}”转换为类型“Rcpp::List{aka Rcpp::Vector}”
返回一个_testlist.test;
^~~~
make:**[/usr/lib64/R/etc/Makeconf:141:testlist.o]错误1
错误:包“testlist”的编译失败
*正在删除“/tmp/RtmppNxPq5/devtools_install_f654fb60a32/testlist”
我做错了什么?简单的打字错误:
return a_testlist.test;
需要:
return a_testlist.test();
不过,您应该考虑阅读VIGNETE来适当地暴露类。
简单类型:
return a_testlist.test;
需要:
return a_testlist.test();
不过,你应该考虑阅读VIGNETE来适当地暴露类。
这是有效的,但是只有在我擦拭目录后重新开始。我省略了()是因为遇到了这个问题中的问题:,但这可能只是为了声明类的实例,而不是调用方法。我阅读了这个小插曲,但没有看到它在本例中添加了什么,因为我已经在使用/[[Rcpp::export]]
。它似乎更多地是关于直接R的整个类,这肯定不是我想要做的,或者我误解了吗?注释1:TheFoo
是一个新的类初始化,而这里是一个被调用的方法。注释2:modules组件是关于在R中提供整个类的。如果您不需要它作为一个特性,那么只需继续当前的类声明和第二个方法导出。但这可能更容易出错。这是可行的,但只有在我擦除目录并重新开始之后。我省略了()是因为遇到了这个问题中的问题:,但这可能只是为了声明类的实例,而不是调用方法。我阅读了这个小插曲,但没有看到它在本例中添加了什么,因为我已经在使用/[[Rcpp::export]]
。它似乎更多地是关于直接R的整个类,这肯定不是我想要做的,或者我误解了吗?注释1:TheFoo
是一个新的类初始化,而这里是一个被调用的方法。注释2:modules组件是关于在R中提供整个类的。如果您不需要它作为一个特性,那么只需继续当前的类声明和第二个方法导出。不过,它可能更容易出错。