22 #ifndef Rcpp__DataFrame_h
23 #define Rcpp__DataFrame_h
30 Rf_setAttrib(
df, R_NamesSymbol, Rf_allocVector(STRSXP, 0));
31 Rf_setAttrib(
df, R_RowNamesSymbol, Rf_allocVector(INTSXP, 0));
32 Rf_setAttrib(
df, R_ClassSymbol, Rf_mkString(
"data.frame"));
37 template <
template <
class>
class StoragePolicy>
54 if (*
this != other)
set__(other);
70 SEXP rn = R_NilValue ;
71 SEXP att = ATTRIB( Parent::get__() ) ;
72 while( att != R_NilValue ){
73 if( TAG(att) == R_RowNamesSymbol ) {
81 if (TYPEOF(rn) == INTSXP && LENGTH(rn) == 2 && INTEGER(rn)[0] == NA_INTEGER)
82 return std::abs(INTEGER(rn)[1]);
93 void push_back(
const T&
object,
const std::string& name ){
104 template <
typename T>
121 #include <Rcpp/generated/DataFrame_generated.h>
125 if( ::Rf_inherits( x,
"data.frame" )){
135 bool invalid_column_size =
false;
139 if (Rf_xlength(*it) > max_rows) {
140 max_rows = Rf_xlength(*it);
144 if (Rf_xlength(*it) == 0 || ( Rf_xlength(*it) > 1 && max_rows % Rf_xlength(*it) != 0 )) {
146 invalid_column_size =
true;
149 if (invalid_column_size) {
150 warning(
"Column sizes are not equal in DataFrame::push_back, object degrading to List\n");
152 set__(Parent::get__());
157 bool use_default_strings_as_factors = true ;
158 bool strings_as_factors = true ;
159 int strings_as_factors_index = -1 ;
160 R_xlen_t n = obj.
size() ;
162 if( !
names.isNULL() ){
163 for(
int i=0; i<n; i++){
164 if(
names[i] ==
"stringsAsFactors" ){
165 strings_as_factors_index = i ;
166 use_default_strings_as_factors = false ;
167 if( !as<bool>(obj[i]) ) strings_as_factors = false ;
172 if( use_default_strings_as_factors )
174 SEXP as_df_symb = Rf_install(
"as.data.frame");
175 SEXP strings_as_factors_symb = Rf_install(
"stringsAsFactors");
177 obj.
erase(strings_as_factors_index) ;
178 names.erase(strings_as_factors_index) ;
180 Shield<SEXP> call( Rf_lang3(as_df_symb, obj, Rf_ScalarLogical(strings_as_factors) ) ) ;
181 SET_TAG( CDDR(call), strings_as_factors_symb ) ;
AttributeProxy attr(const std::string &name)
static DataFrame_Impl from_list(Parent obj)
void push_back(const T &object)
void push_front(const T &object)
DataFrame_Impl & operator=(DataFrame_Impl &other)
DataFrame_Impl(const DataFrame_Impl &other)
void set_type_after_push()
Vector< VECSXP, StoragePolicy > Parent
void push_front(const T &object, const std::string &name)
static DataFrame_Impl create()
void push_back(const T &object, const std::string &name)
DataFrame_Impl & operator=(SEXP x)
iterator erase(int position)
traits::r_vector_iterator< RTYPE, PreserveStorage >::type iterator
void push_back(const T &object)
void push_front(const T &object)
double df(double x, double df1, double df2, int lg)
SEXP convert_using_rfunction(SEXP x, const char *const fun)
void warning(const char *fmt, Args &&... args)
SEXP Rcpp_fast_eval(SEXP expr, SEXP env)
DataFrame_Impl< PreserveStorage > DataFrame