[Rcpp-commits] r4301 - in pkg/Rcpp: . inst/include/Rcpp inst/include/Rcpp/generated src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Apr 2 20:24:01 CEST 2013


Author: romain
Date: 2013-04-02 20:24:00 +0200 (Tue, 02 Apr 2013)
New Revision: 4301

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/DataFrame.h
   pkg/Rcpp/inst/include/Rcpp/generated/DataFrame_generated.h
   pkg/Rcpp/src/api.cpp
Log:
deal with stringsAsFactors

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2013-04-02 14:24:48 UTC (rev 4300)
+++ pkg/Rcpp/ChangeLog	2013-04-02 18:24:00 UTC (rev 4301)
@@ -4,7 +4,11 @@
         uses List::create and then feeds to the DataFrame constructor, which 
         seems to work better than the previous approach of calling back to the 
         data.frame function in R
+        * include/Rcpp/DataFrame.h : private function from_list, to help 
+        the new implementation of DataFrame::create
+        * src/api.cpp : impl of DataFrame::from_list
         
+        
 2013-03-31  Dirk Eddelbuettel  <edd at debian.org>
 
 	* debian/control (Build-Depends): Modified for Debian-only rebuilds

Modified: pkg/Rcpp/inst/include/Rcpp/DataFrame.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/DataFrame.h	2013-04-02 14:24:48 UTC (rev 4300)
+++ pkg/Rcpp/inst/include/Rcpp/DataFrame.h	2013-04-02 18:24:00 UTC (rev 4301)
@@ -2,7 +2,7 @@
 //
 // DataFrame.h: Rcpp R/C++ interface class library -- data frames
 //
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -48,6 +48,7 @@
 
     private:
         void set_sexp(SEXP x) ;
+        static DataFrame from_list( Rcpp::List ) ;
         
     } ;
         

Modified: pkg/Rcpp/inst/include/Rcpp/generated/DataFrame_generated.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/generated/DataFrame_generated.h	2013-04-02 14:24:48 UTC (rev 4300)
+++ pkg/Rcpp/inst/include/Rcpp/generated/DataFrame_generated.h	2013-04-02 18:24:00 UTC (rev 4301)
@@ -26,121 +26,121 @@
 
 template <typename T1>
 static DataFrame create( const T1& t1 ) {
-    return DataFrame( List::create( t1 ) ) ;
+    return DataFrame::from_list( List::create( t1 ) ) ;
 } 
 
 
 template <typename T1, typename T2>
 static DataFrame create( const T1& t1, const T2& t2 ) {
-    return DataFrame( List::create( t1, t2 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3 ) {
-    return DataFrame( List::create( t1, t2, t3 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4 ) {
-    return DataFrame( List::create( t1, t2, t3, t4 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19 ) ) ;
 } 
 
 
 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20>
 static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20 ) {
-    return DataFrame( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20 ) ) ;
+    return DataFrame::from_list( List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20 ) ) ;
 } 
 
 #endif

Modified: pkg/Rcpp/src/api.cpp
===================================================================
--- pkg/Rcpp/src/api.cpp	2013-04-02 14:24:48 UTC (rev 4300)
+++ pkg/Rcpp/src/api.cpp	2013-04-02 18:24:00 UTC (rev 4301)
@@ -1208,6 +1208,38 @@
     } 
     int DataFrame::nrows() const { return Rf_length( VECTOR_ELT(m_sexp, 0) ); }
         
+    DataFrame DataFrame::from_list( Rcpp::List obj ){
+        bool use_default_strings_as_factors = true ;
+        bool strings_as_factors = true ;
+        int strings_as_factors_index = -1 ;
+        int n = obj.size() ;
+        CharacterVector names = obj.attr( "names" ) ;
+        if( !names.isNULL() ){
+            for( int i=0; i<n; i++){
+                if( names[i] == "stringsAsFactors" ){
+                    strings_as_factors_index = i ;
+                    use_default_strings_as_factors = false ;        
+                    if( !as<bool>(obj[i]) ) strings_as_factors = false ;
+                    break ;         
+                }
+            }
+        }
+        if( use_default_strings_as_factors ) 
+            return DataFrame(obj) ;
+        SEXP as_df_symb = Rf_install("as.data.frame");
+        SEXP strings_as_factors_symb = Rf_install("stringsAsFactors");
+        
+        obj.erase(strings_as_factors_index) ;
+        names.erase(strings_as_factors_index) ;
+        obj.attr( "names") = names ;
+        SEXP call  = PROTECT( Rf_lang3(as_df_symb, obj, wrap( strings_as_factors ) ) ) ;
+        SET_TAG( CDDR(call),  strings_as_factors_symb ) ;   
+        SEXP res = PROTECT( Evaluator::run( call ) ) ; 
+        DataFrame out( res ) ;
+        UNPROTECT(2) ;
+        return out ;
+    }
+    
     // }}}
     
 } // namespace Rcpp



More information about the Rcpp-commits mailing list