DataFrameJoinVisitors::DataFrameJoinVisitors(const DataFrame& left_, const DataFrame& right_, const SymbolVector& names_left, const SymbolVector& names_right, bool warn_, bool na_match) : left(left_), right(right_), visitor_names_left(names_left), visitor_names_right(names_right), visitors(names_left.size()), warn(warn_) { IntegerVector indices_left = names_left.match_in_table(RCPP_GET_NAMES(left)); IntegerVector indices_right = names_right.match_in_table(RCPP_GET_NAMES(right)); const int nvisitors = indices_left.size(); if (indices_right.size() != nvisitors) { stop("Different size of join column index vectors"); } for (int i = 0; i < nvisitors; i++) { const SymbolString& name_left = names_left[i]; const SymbolString& name_right = names_right[i]; if (indices_left[i] == NA_INTEGER) { stop("'%s' column not found in lhs, cannot join", name_left.get_utf8_cstring()); } if (indices_right[i] == NA_INTEGER) { stop("'%s' column not found in rhs, cannot join", name_right.get_utf8_cstring()); } visitors[i] = join_visitor( Column(left[indices_left[i] - 1], name_left), Column(right[indices_right[i] - 1], name_right), warn, na_match ); } }
DataFrameJoinVisitors::DataFrameJoinVisitors(const Rcpp::DataFrame& left_, const Rcpp::DataFrame& right_, Rcpp::CharacterVector names_left, Rcpp::CharacterVector names_right, bool warn_ ) : left(left_), right(right_), visitor_names_left(names_left), visitor_names_right(names_right), nvisitors(names_left.size()), visitors(nvisitors), warn(warn_) { std::string name_left, name_right ; IntegerVector indices_left = Language( "match", names_left, RCPP_GET_NAMES(left) ).fast_eval() ; IntegerVector indices_right = Language( "match", names_right, RCPP_GET_NAMES(right) ).fast_eval() ; for( int i=0; i<nvisitors; i++){ name_left = names_left[i] ; name_right = names_right[i] ; if( indices_left[i] == NA_INTEGER ){ stop( "'%s' column not found in lhs, cannot join" ) ; } if( indices_right[i] == NA_INTEGER ){ stop( "'%s' column not found in rhs, cannot join" ) ; } visitors[i] = join_visitor( left[indices_left[i]-1], right[indices_right[i]-1], name_left, name_right, warn ) ; } }
DataFrameSubsetVisitors::DataFrameSubsetVisitors( const Rcpp::DataFrame& data_, const Rcpp::CharacterVector& names ) : data(data_), visitors(), visitor_names(names), nvisitors(visitor_names.size()) { std::string name ; int n = names.size() ; IntegerVector indices = Language( "match", names, RCPP_GET_NAMES(data) ).fast_eval() ; for( int i=0; i<n; i++){ int pos = indices[i] ; if( pos == NA_INTEGER ){ name = (String)names[i] ; stop( "unknown column '%s' ", name ) ; } visitors.push_back(subset_visitor( data[pos-1] )) ; } }