2017-10-14 1 views
0

에서이 수정 질문모호한 오버로드 연산자는 특히 Rcpp

연구에서

이며, 나 또한 데이터 프레임은 두 개의 문자로 된 문자열이 포함 Row_Labels라는이 string def;로 Rcpp 나는 문자열, "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>'))

내가 도움을 주셔서 감사합니다이 개정 희망 더 도움이 됨

+0

'using namespace Rcpp;를 사용하지 마십시오. using namespace std;'명시 적'::'참조를 사용하라. –

+0

_complete 및 reproducible_ 예제를 제공하십시오. 이것은 하나가 아닙니다. –

+0

감사합니다. 두 개의 네임 스페이스 문을 제거했습니다. 오류가 계속 발생합니다. 여기에 완전한 기능을 붙여 넣으려고했으나 오류가 발생했습니다. – K17

답변

1

아주 간단한 오류가 있습니다 : 행과 열 레이블이 DateFrame 인 경우 Row_Labels[i];에서와 같이 색인을 생성 할 수 없습니다. 이는 벡터가 아닙니다. 수정 : 대신 벡터를 사용하십시오. 또한 nrow() 대신 length()을 사용해야합니다. 그래서 다음과 같이 잘 컴파일됩니다 :

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

나는 또한 조여서 조금 줄입니다.

+0

고맙습니다. R에서 데이터 프레임을 호출 할 때 벡터를 사용하지 않으면 여기에 함수가 호출 될 때 문제가 발생합니까? – K17

+0

글쎄, 증명은 그것이 작동하는지 여부입니다. 교훈을 가져 주셔서 대단히 감사합니다. – K17

+1

물론'DataFrame'을 사용하여 벡터 등을 전달할 수 있지만 추출해야합니다. [Rcpp Gallery] (http://gallery.rcpp.org)에서 몇 가지 예를 참조하십시오. –

관련 문제