Skip to content

Commit eaded60

Browse files
implementation of DataFrame::nrows that does not have to pay the price of R wanting to be too smart. #124
1 parent f075788 commit eaded60

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

inst/include/Rcpp/DataFrame.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ namespace Rcpp{
2020
~DataFrame_Impl() ;
2121

2222
int nrows() const {
23-
SEXP rn = Rf_getAttrib( *this, R_RowNamesSymbol ) ;
24-
if( TYPEOF(rn) == INTSXP && LENGTH(rn) == 2 && INTEGER(rn)[0] == NA_INTEGER ) return INTEGER(rn)[1] ;
23+
SEXP rn = R_NilValue ;
24+
SEXP att = ATTRIB( Storage::get__() );
25+
while( att != R_NilValue ){
26+
if( TAG(att) == R_RowNamesSymbol ){
27+
rn = CAR(att) ;
28+
}
29+
att = CDR(att) ;
30+
}
2531
if( Rf_isNull(rn) ) return 0 ;
32+
if( TYPEOF(rn) == INTSXP && LENGTH(rn) == 2 && INTEGER(rn)[0] == NA_INTEGER ) return -INTEGER(rn)[1] ;
2633
return LENGTH(rn) ;
2734
}
2835

0 commit comments

Comments
 (0)