简体   繁体   English

Rcpp 中的二义性重载运算符

[英]ambiguous overload operator specifically in Rcpp

This is a revised question这是一个修改后的问题

In r, and Rcpp I have a string declared as string def;在 r 和 Rcpp 中,我有一个声明为string def; I also have a data frame called Row_Labels that contains two-letter strings, "AA", "BB", etc. Now I am trying to do this..我还有一个名为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);

}

I am getting an error that is... 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>'))我收到一个错误是... 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>'))

I appreciate the help and hope this revision is more helpful我感谢您的帮助,并希望此修订版更有帮助

You have a pretty simple error there: If row and column labels are of type DateFrame then you cannot index as you do in Row_Labels[i];你有一个非常简单的错误:如果行和列标签是DateFrame类型,那么你不能像在Row_Labels[i];Row_Labels[i];索引Row_Labels[i]; -- these are not vectors. ——这些不是载体。 Fix: use vectors instead.修复:改用向量。 This also requires to use length() rather than nrow() .这也需要使用length()而不是nrow() So the following compiles fine:所以以下编译正常:

#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);
}

I also tightened and shortend it a little.我也收紧并缩短了一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM