Skip to content

Commit

Permalink
Work around match issues in R 3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed May 26, 2016
1 parent 1defb3b commit 7168759
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
4 changes: 0 additions & 4 deletions inst/include/dplyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ namespace dplyr {
DataFrame subset( DataFrame df, const Index& indices, CharacterVector classes) ;
void check_attribute_compatibility( SEXP left, SEXP right) ;
bool same_levels( SEXP left, SEXP right ) ;

inline IntegerVector r_match( SEXP x, SEXP y) {
return Language( "match", x, y ).fast_eval() ;
}
}
dplyr::Result* get_handler( SEXP, const dplyr::LazySubsets&, const Environment& ) ;
dplyr::Result* nth_prototype( SEXP call, const dplyr::LazySubsets& subsets, int nargs) ;
Expand Down
3 changes: 1 addition & 2 deletions inst/include/tools/SymbolMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace dplyr{

class SymbolMap {
public:
SymbolMap(): lookup(), r_match( "match" ), names(){}
SymbolMap(): lookup(), names(){}

SymbolMapIndex insert( SEXP name ){
if( TYPEOF(name) == SYMSXP ) {
Expand Down Expand Up @@ -117,7 +117,6 @@ namespace dplyr{


dplyr_hash_map<SEXP, int> lookup ;
Function r_match ;
CharacterVector names ;

} ;
Expand Down
25 changes: 25 additions & 0 deletions inst/include/tools/match.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef dplyr_tools_match_h
#define dplyr_tools_match_h


namespace dplyr {

class RMatch {
public:
RMatch() : match_fun("match", R_BaseEnv) {}
IntegerVector operator()(SEXP x, SEXP y) {
return match_fun(x, y, NA_INTEGER, CharacterVector());
}

private:
Function match_fun;
};

inline IntegerVector r_match( SEXP x, SEXP y ) {
static RMatch m;
return m(x, y);
}

};

#endif
1 change: 1 addition & 0 deletions inst/include/tools/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define dplyr_tools_tools_H

#include <tools/Encoding.h>
#include <tools/match.h>
#include <tools/SymbolMap.h>
#include <tools/StringUTF8.h>
#include <tools/complex.h>
Expand Down
3 changes: 1 addition & 2 deletions src/dplyr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,8 +1208,7 @@ SEXP resolve_vars( List new_groups, CharacterVector names){
}
// check that s is indeed in the data

Function match( "match" ) ;
int pos = as<int>(match( CharacterVector::create(PRINTNAME(s)), names));
int pos = as<int>(r_match( CharacterVector::create(PRINTNAME(s)), names ));
if( pos == NA_INTEGER){
stop("unknown variable to group by : %s", CHAR(PRINTNAME(s))) ;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-group-by.r
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,6 @@ test_that( "group_by supports column (#1012)", {
test_that("group_by handles encodings (#1507)", {
df <- data.frame(x=1:3, Eng=2:4)
names(df) <- enc2utf8(c("\u00e9", "Eng"))
res <- group_by_(df, iconv("\u00e9", to = "latin1") )
res <- group_by_(df, iconv("\u00e9", from = "UTF-8", to = "latin1") )
expect_equal( names(res), names(df) )
})
2 changes: 1 addition & 1 deletion tests/testthat/test-joins.r
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ test_that( "left_join handles mix of encodings in column names (#1571)", {
names(df1)[1] <- "l\u00f8penummer"

df2 <- tibble::data_frame(x = 1:6, baz = 1:6)
names(df2)[1] <- iconv( "l\u00f8penummer", to = "latin1" )
names(df2)[1] <- iconv( "l\u00f8penummer", from = "UTF-8", to = "latin1" )

expect_message( res <- left_join( df1, df2 ) )
expect_equal( names(res), c("l\u00f8penummer", "foo", "baz") )
Expand Down

0 comments on commit 7168759

Please sign in to comment.