Skip to content

Commit

Permalink
relax white_list. tidyverse#1105
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Apr 30, 2015
1 parent f22f9fa commit a0d0efc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 57 deletions.
52 changes: 19 additions & 33 deletions inst/include/dplyr/white_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,27 @@
#define dplyr_white_list_H

namespace dplyr{

inline bool is_bare_vector( SEXP x){
SEXP att = ATTRIB(x) ;

// only allow R_Names. as in R's do_isvector
while( att != R_NilValue ){
SEXP tag = TAG(att) ;
if( !( tag == R_NamesSymbol || tag == Rf_install("comment") ) ) return false ;
att = CDR(att) ;
}

return true ;
}

inline bool white_list(SEXP x){
if( Rf_isMatrix(x) ) {
// might have to refine later
return true ;
}
switch( TYPEOF(x) ){
case INTSXP: return Rf_inherits(x, "Date") || Rf_inherits(x, "POSIXct" ) || Rf_inherits(x, "factor" ) || Rf_inherits(x, "AsIs") || is_bare_vector( x ) ;
case REALSXP: return Rf_inherits(x, "Date") || Rf_inherits(x, "POSIXct" ) || Rf_inherits(x,"difftime") || Rf_inherits(x, "AsIs") || is_bare_vector( x ) ;
case LGLSXP: return Rf_inherits(x, "AsIs") || is_bare_vector( x ) ;
case STRSXP: return Rf_inherits(x, "AsIs") || is_bare_vector( x ) ;
case CPLXSXP: return Rf_inherits(x, "AsIs") || is_bare_vector( x ) ;

case VECSXP: {
if( Rf_inherits( x, "data.frame" ) ) return true ;
return ! Rf_inherits(x, "POSIXlt") && is_bare_vector( x ) ;
inline bool white_list(SEXP x){
if( Rf_isMatrix(x) ) {
// might have to refine later
return true ;
}
switch( TYPEOF(x) ){
case INTSXP: return true ;
case REALSXP: return true ;
case LGLSXP: return true ;
case STRSXP: return true ;
case CPLXSXP: return true ;
case VECSXP: {
if( Rf_inherits( x, "POSIXlt") ) return false ;
return true ;
}

default: break ;
}
return false ;
}

default: break ;
}
return false ;
}

}
#endif
Expand Down
24 changes: 0 additions & 24 deletions src/dplyr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,25 +1019,6 @@ void push_back( Container& x, typename Container::value_type value, int n ){
x.push_back( value ) ;
}

std::string get_unsupported_attributes( SEXP v ){
SEXP att = ATTRIB(v) ;
std::stringstream s ;
int i = 0 ;

// only allow R_Names. as in R's do_isvector
while( att != R_NilValue ){
SEXP tag = TAG(att) ;
if( !( tag == R_NamesSymbol || tag == Rf_install("comment") ) ) {
if( i > 0 ) s << ", " ;
i++ ;
s << CHAR(PRINTNAME(tag)) ;
}
att = CDR(att) ;
}

return s.str() ;
}

void assert_all_white_list(const DataFrame& data){
// checking variables are on the white list
int nc = data.size() ;
Expand All @@ -1053,11 +1034,6 @@ void assert_all_white_list(const DataFrame& data){
name_i.get_cstring() , get_single_class(v) );
}

std::string unsupported_attributes = get_unsupported_attributes(v) ;

stop( "column '%s' of type %s has unsupported attributes: %s",
name_i.get_cstring() , get_single_class(v), unsupported_attributes );

}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ using namespace Rcpp ;

namespace dplyr{

inline bool is_bare_vector( SEXP x){
SEXP att = ATTRIB(x) ;

// only allow R_Names. as in R's do_isvector
while( att != R_NilValue ){
SEXP tag = TAG(att) ;
if( !( tag == R_NamesSymbol || tag == Rf_install("comment") ) ) return false ;
att = CDR(att) ;
}

return true ;
}


// -------------- (int,lgl)
template <int LHS_RTYPE, int RHS_RTYPE>
inline size_t hash_int_int( JoinVisitorImpl<LHS_RTYPE,RHS_RTYPE>& joiner, int i){
Expand Down

0 comments on commit a0d0efc

Please sign in to comment.