[Rcpp-commits] r1176 - in pkg/Rcpp/inst: . include/Rcpp unitTests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu May 6 10:16:37 CEST 2010
Author: romain
Date: 2010-05-06 10:16:35 +0200 (Thu, 06 May 2010)
New Revision: 1176
Modified:
pkg/Rcpp/inst/ChangeLog
pkg/Rcpp/inst/include/Rcpp/DataFrame.h
pkg/Rcpp/inst/include/Rcpp/DataFrame_generated.h
pkg/Rcpp/inst/unitTests/runit.DataFrame.R
Log:
DataFrame::create now uses data.frame instead of as.data.frame to allow stringsAsFactors to work
Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog 2010-05-06 06:59:05 UTC (rev 1175)
+++ pkg/Rcpp/inst/ChangeLog 2010-05-06 08:16:35 UTC (rev 1176)
@@ -2,13 +2,17 @@
* inst/include/Rcpp/DataFrame.h: DataFrame( RObject::SlotProxy ) and
DataFrame( RObject::AttributeProxy ) constructors
+
+ * inst/include/Rcpp/DataFrame.h: DataFrame::create now uses the R function
+ data.frame and not as.data.frame, which respects the stringsAsFactors
+ argument.
2010-05-05 Romain Francois <romain at r-enthusiasts.com>
* inst/include/Rcpp/S4.h: S4 gains a "is" method to identify if an object
is of a given S4 class, following Doug's advice in lme4a
- * inst/include/RcppCommon.h: new STL-like algorithms Rcpp::any and Rcpp::any_if
+ * inst/include/Rcpp/algo.h: new STL-like algorithms Rcpp::any and Rcpp::any_if
* inst/include/Rcpp/Vector.h: Vector gains a constructor taking an
RObject::SlotProxy and a constructor taking an RObject::AttributeProxy,
Modified: pkg/Rcpp/inst/include/Rcpp/DataFrame.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/DataFrame.h 2010-05-06 06:59:05 UTC (rev 1175)
+++ pkg/Rcpp/inst/include/Rcpp/DataFrame.h 2010-05-06 08:16:35 UTC (rev 1176)
@@ -64,8 +64,12 @@
private:
void set(SEXP x) throw(not_compatible) {
- SEXP y = internal::convert_using_rfunction( x, "as.data.frame" ) ;
- setSEXP( y ) ;
+ if( ::Rf_inherits( x, "data.frame" )){
+ setSEXP( x ) ;
+ } else{
+ SEXP y = internal::convert_using_rfunction( x, "as.data.frame" ) ;
+ setSEXP( y ) ;
+ }
}
} ;
Modified: pkg/Rcpp/inst/include/Rcpp/DataFrame_generated.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/DataFrame_generated.h 2010-05-06 06:59:05 UTC (rev 1175)
+++ pkg/Rcpp/inst/include/Rcpp/DataFrame_generated.h 2010-05-06 08:16:35 UTC (rev 1176)
@@ -27,220 +27,280 @@
template <typename T1>
static DataFrame create( const T1& t1 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
template <typename T1, typename T2>
static DataFrame create( const T1& t1, const T2& t2 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
template <typename T1, typename T2, typename T3>
static DataFrame create( const T1& t1, const T2& t2, const T3& t3 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
template <typename T1, typename T2, typename T3, typename T4>
static DataFrame create( const T1& t1, const T2& t2, const T3& t3, const T4& t4 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8, t9 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
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 ) throw(not_compatible){
- return DataFrame(
- internal::convert_using_rfunction(
- List::create( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20 ),
- "as.data.frame"
- ) ) ;
+ try{
+ return DataFrame(
+ internal::try_catch(
+ ::Rf_lcons( ::Rf_install( "data.frame"), pairlist( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20 ) )
+ ) ) ;
+ } catch( eval_error& __ex__){
+ throw not_compatible("error calling the data.frame function") ;
+ }
}
Modified: pkg/Rcpp/inst/unitTests/runit.DataFrame.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.DataFrame.R 2010-05-06 06:59:05 UTC (rev 1175)
+++ pkg/Rcpp/inst/unitTests/runit.DataFrame.R 2010-05-06 08:16:35 UTC (rev 1176)
@@ -77,4 +77,19 @@
}
+test.DataFrame.CreateTwo.stringsAsFactors <- function() {
+ DF <- data.frame(a=1:3, b=c("a","b","c"), stringsAsFactors = FALSE )
+ fun <- cppfunction( signature(), '
+ IntegerVector v = IntegerVector::create(1,2,3);
+ std::vector<std::string> s(3);
+ s[0] = "a";
+ s[1] = "b";
+ s[2] = "c";
+ return DataFrame::create(
+ _["a"] = v,
+ _["b"] = s,
+ _["stringsAsFactors"] = false );
+ ' )
+ checkEquals( fun(), DF, msg = "DataFrame create2 stringsAsFactors = false")
+}
More information about the Rcpp-commits
mailing list