Skip to content

Commit

Permalink
up Rcpp dep to 0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Aug 7, 2015
1 parent e5cdcc1 commit ef34d76
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 45 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Suggests:
methods
VignetteBuilder: knitr
LazyData: yes
LinkingTo: Rcpp (>= 0.11.6),
LinkingTo: Rcpp (>= 0.12.0),
BH (>= 1.58.0-1)
License: MIT + file LICENSE
Collate:
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
* Introduced the SubsetVectorVisitor class and various implementations, and the
DataFrameSubsetVisitors. Simplified the VectorVisitor and DataFrameVisitors.
This deals with several performance regression problems.


* up Rcpp dependency to 0.12.0, and remove the obsolete SHALLOW_COPY workaround

# dplyr 0.4.2

This is a minor release containing fixes for a number of crashes and issues identified by R CMD CHECK. There is one new "feature": dplyr no longer complains about unrecognised attributes, and instead just copies them over to the output.
Expand Down
12 changes: 0 additions & 12 deletions inst/include/dplyr/workarounds.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
#ifndef DPLYR_WORKAROUND_H
#define DPLYR_WORKAROUND_H

// Rcpp workaround - get rid of this once we have a released version
// greater than 0.11.6
#if RCPP_DEV_VERSION > RcppDevVersion(0,11,6,0)
#define SHALLOW_COPY(__NAME__,__SOURCE__) DataFrame __NAME__(shallow_copy(__SOURCE__))
#else
#define SHALLOW_COPY(__NAME__,__SOURCE__) \
SEXP shallow_copied = PROTECT( shallow_copy(__SOURCE__) ) ; \
DataFrame __NAME__(shallow_copied) ; \
UNPROTECT(1)
#endif

// C/R API workaround
// installChar was introduced in R 3.2.0
#ifndef installChar
#define installChar(x) Rf_install(CHAR(x))
Expand Down
8 changes: 4 additions & 4 deletions src/dplyr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ IntegerVector match_data_frame( DataFrame x, DataFrame y){
// [[Rcpp::export]]
DataFrame grouped_df_impl( DataFrame data, ListOf<Symbol> symbols, bool drop ){
assert_all_white_list(data);
SHALLOW_COPY(copy,data) ;
DataFrame copy( shallow_copy(data));
copy.attr("vars") = symbols ;
copy.attr("drop") = drop ;
if( !symbols.size() )
Expand Down Expand Up @@ -1558,7 +1558,7 @@ DataFrame build_index_adj(DataFrame df, ListOf<Symbol> symbols ){

// [[Rcpp::export]]
DataFrame grouped_df_adj_impl( DataFrame data, ListOf<Symbol> symbols, bool drop ){
SHALLOW_COPY(copy,data) ;
DataFrame copy( shallow_copy(data));
copy.attr("vars") = symbols ;
copy.attr("drop") = drop ;
return build_index_adj(data, symbols) ;
Expand Down Expand Up @@ -2019,7 +2019,7 @@ SEXP n_distinct(SEXP x, bool na_rm = false){

// [[Rcpp::export]]
DataFrame as_regular_df(DataFrame df){
SHALLOW_COPY(copy,df) ;
DataFrame copy( shallow_copy(df));
SET_ATTRIB(copy, strip_group_attributes(df)) ;
SET_OBJECT(copy, OBJECT(df)) ;
copy.attr("class") = CharacterVector::create("data.frame") ;
Expand All @@ -2028,7 +2028,7 @@ DataFrame as_regular_df(DataFrame df){

// [[Rcpp::export]]
DataFrame ungroup_grouped_df( DataFrame df){
SHALLOW_COPY(copy,df) ;
DataFrame copy( shallow_copy(df));
SET_ATTRIB(copy, strip_group_attributes(df)) ;
return copy ;
}
Expand Down
50 changes: 23 additions & 27 deletions src/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,59 @@ using namespace dplyr ;

SEXP select_not_grouped( const DataFrame& df, const CharacterVector& keep, CharacterVector new_names ){
CharacterVector names = df.names() ;
IntegerVector positions = match( keep, names );
int n = keep.size() ;
IntegerVector positions = match( keep, names );
int n = keep.size() ;
List res(n) ;
for( int i=0; i<n; i++){
int pos = positions[i] ;
if( pos < 1 || pos > df.size() ){
std::stringstream s ;
if( pos == NA_INTEGER ){
if( pos == NA_INTEGER ){
s << "NA" ;
} else {
s << pos ;
s << pos ;
}
stop( "invalid column index : %d for variable: %s = %s",
stop( "invalid column index : %d for variable: %s = %s",
s.str(), CHAR((SEXP)new_names[i]), CHAR((SEXP)keep[i]) );
}
res[i] = df[ pos-1 ] ;
res[i] = df[ pos-1 ] ;
}
copy_most_attributes(res, df) ;
res.names() = new_names ;
return res ;
res.names() = new_names ;
return res ;
}

DataFrame select_grouped( GroupedDataFrame gdf, const CharacterVector& keep, CharacterVector new_names ){
int n = keep.size() ;
DataFrame copy = select_not_grouped( gdf.data(), keep, new_names );
// handle vars attribute : make a shallow copy of the list and alter

// handle vars attribute : make a shallow copy of the list and alter
// its names attribute
//
// note: this does not need the SHALLOW_COPY macro because the
// Vector(SEXP) ctor is fine
List vars = shallow_copy( copy.attr("vars") );

List vars = shallow_copy( copy.attr("vars") );

int nv = vars.size() ;
for( int i=0; i<nv; i++){
SEXP s = PRINTNAME(vars[i]) ;
int j = 0;
int j = 0;
for( ; j < n; j++){
if( s == keep[j] ){
vars[i] = Rf_installChar( new_names[j] );
vars[i] = Rf_installChar( new_names[j] );
}
}
}

copy.attr("vars") = vars ;

// hangle labels attribute
// make a shallow copy of the data frame and alter its names attributes
if( !Rf_isNull( copy.attr("labels" ) ) ){

DataFrame original_labels( copy.attr("labels" ) ) ;
SHALLOW_COPY(labels,original_labels) ;

DataFrame labels( shallow_copy(original_labels));
CharacterVector label_names = clone<CharacterVector>( labels.names() ) ;
IntegerVector positions = match( label_names, keep );

IntegerVector positions = match( label_names, keep );
int nl = label_names.size() ;
for( int i=0; i<nl; i++){
label_names[i] = new_names[ positions[i]-1 ] ;
Expand All @@ -76,9 +73,8 @@ DataFrame select_grouped( GroupedDataFrame gdf, const CharacterVector& keep, Cha
DataFrame select_impl( DataFrame df, CharacterVector vars ){
check_valid_colnames(df) ;
if( is<GroupedDataFrame>(df) ){
return select_grouped( GroupedDataFrame(df), vars, vars.names() ) ;
return select_grouped( GroupedDataFrame(df), vars, vars.names() ) ;
} else {
return select_not_grouped(df, vars, vars.names() ) ;
return select_not_grouped(df, vars, vars.names() ) ;
}
}

0 comments on commit ef34d76

Please sign in to comment.