不明确的重载运算符,特别是在 Rcpp 中
ambiguous overload operator specifically in Rcpp
这是修改后的问题
在 r 和 Rcpp 中,我有一个字符串声明为 string def;
我还有一个名为 Row_Labels
的数据框,其中包含两个字母的字符串,"AA"、"BB" 等。
现在我正在尝试这样做..
#include <Rcpp.h>
#include <string.h>
//using namespace Rcpp;
//using namespace std;
// [[Rcpp::export]]
Rcpp::DataFrame process_Data(Rcpp::DataFrame df,Rcpp::DataFrame Row_Labels, Rcpp::DataFrame Column_Labels){
Rcpp::Rcout << "Test value from 'cout' " << std::endl;
Rcpp::Rcout << "Number of rows in df = " << df.nrow() << std::endl;
std::string abc;
abc = "test value";
std::string def;
def = "zz";
for(int i = 0; i < Row_Labels.nrow() ; i++)
{
def = Row_Labels[i]; // error here
Rcpp::Rcout << "Row_Labels = " << i;
Rcpp::Rcout << i << " " << Row_Labels[i] << std::endl; // error here
}
return Rcpp::DataFrame::create(Rcpp::_["a"]= df);
}
我收到一个错误... use of overload operator'=' is ambiguous (with operand types 'string' (aka 'based_string <char, char traits <char>, allocator <char> >') and 'Proxy' (aka 'generic proxy<19>'))
非常感谢您的帮助,希望这次修订更有帮助
你有一个非常简单的错误:如果行和列标签是 DateFrame
类型,那么你不能像在 Row_Labels[i];
中那样建立索引——这些不是向量。修复:改用向量。这也需要使用 length()
而不是 nrow()
。所以下面的编译很好:
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::DataFrame process_Data(Rcpp::DataFrame df,
Rcpp::CharacterVector Row_Labels,
Rcpp::CharacterVector Column_Labels){
Rcpp::Rcout << "Test value from 'cout' " << std::endl;
Rcpp::Rcout << "Number of rows in df = " << df.nrow() << std::endl;
std::string abc = "test value";
std::string def = "zz";
for(int i = 0; i < Row_Labels.length() ; i++) {
def = Row_Labels[i]; // error here
Rcpp::Rcout << "Row_Labels = " << i;
Rcpp::Rcout << i << " " << Row_Labels[i] << std::endl; // error here
}
return Rcpp::DataFrame::create(Rcpp::_["a"]= df);
}
我也收紧了一点,缩短了一点。
这是修改后的问题
在 r 和 Rcpp 中,我有一个字符串声明为 string def;
我还有一个名为 Row_Labels
的数据框,其中包含两个字母的字符串,"AA"、"BB" 等。
现在我正在尝试这样做..
#include <Rcpp.h>
#include <string.h>
//using namespace Rcpp;
//using namespace std;
// [[Rcpp::export]]
Rcpp::DataFrame process_Data(Rcpp::DataFrame df,Rcpp::DataFrame Row_Labels, Rcpp::DataFrame Column_Labels){
Rcpp::Rcout << "Test value from 'cout' " << std::endl;
Rcpp::Rcout << "Number of rows in df = " << df.nrow() << std::endl;
std::string abc;
abc = "test value";
std::string def;
def = "zz";
for(int i = 0; i < Row_Labels.nrow() ; i++)
{
def = Row_Labels[i]; // error here
Rcpp::Rcout << "Row_Labels = " << i;
Rcpp::Rcout << i << " " << Row_Labels[i] << std::endl; // error here
}
return Rcpp::DataFrame::create(Rcpp::_["a"]= df);
}
我收到一个错误... use of overload operator'=' is ambiguous (with operand types 'string' (aka 'based_string <char, char traits <char>, allocator <char> >') and 'Proxy' (aka 'generic proxy<19>'))
非常感谢您的帮助,希望这次修订更有帮助
你有一个非常简单的错误:如果行和列标签是 DateFrame
类型,那么你不能像在 Row_Labels[i];
中那样建立索引——这些不是向量。修复:改用向量。这也需要使用 length()
而不是 nrow()
。所以下面的编译很好:
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::DataFrame process_Data(Rcpp::DataFrame df,
Rcpp::CharacterVector Row_Labels,
Rcpp::CharacterVector Column_Labels){
Rcpp::Rcout << "Test value from 'cout' " << std::endl;
Rcpp::Rcout << "Number of rows in df = " << df.nrow() << std::endl;
std::string abc = "test value";
std::string def = "zz";
for(int i = 0; i < Row_Labels.length() ; i++) {
def = Row_Labels[i]; // error here
Rcpp::Rcout << "Row_Labels = " << i;
Rcpp::Rcout << i << " " << Row_Labels[i] << std::endl; // error here
}
return Rcpp::DataFrame::create(Rcpp::_["a"]= df);
}
我也收紧了一点,缩短了一点。