11#include "vctrs.h"
2- #include "utils .h"
2+ #include "arg-counter .h"
33#include "ptype-common.h"
44#include "ptype2.h"
5- #include "arg-counter.h"
5+ #include "type-data-frame.h"
6+ #include "utils.h"
67
78// Initialised at load time
89static SEXP syms_vec_ptype_finalise_dispatch = NULL ;
@@ -11,6 +12,7 @@ static SEXP fns_vec_ptype_finalise_dispatch = NULL;
1112
1213static inline SEXP vec_ptype_slice (SEXP x , SEXP empty );
1314static SEXP s3_type (SEXP x , struct vctrs_arg * x_arg );
15+ static SEXP df_ptype (SEXP x , bool bare );
1416
1517// [[ register() ]]
1618SEXP vctrs_ptype (SEXP x , SEXP x_arg ) {
@@ -32,7 +34,7 @@ SEXP vec_ptype(SEXP x, struct vctrs_arg* x_arg) {
3234 case vctrs_type_character : return vec_ptype_slice (x , vctrs_shared_empty_chr );
3335 case vctrs_type_raw : return vec_ptype_slice (x , vctrs_shared_empty_raw );
3436 case vctrs_type_list : return vec_ptype_slice (x , vctrs_shared_empty_list );
35- case vctrs_type_dataframe : return bare_df_map (x , & col_ptype );
37+ case vctrs_type_dataframe : return df_ptype (x , true );
3638 case vctrs_type_s3 : return s3_type (x , x_arg );
3739 case vctrs_type_scalar : stop_scalar_type (x , x_arg );
3840 }
@@ -54,10 +56,10 @@ static inline SEXP vec_ptype_slice(SEXP x, SEXP empty) {
5456static SEXP s3_type (SEXP x , struct vctrs_arg * x_arg ) {
5557 switch (class_type (x )) {
5658 case vctrs_class_bare_tibble :
57- return bare_df_map (x , & col_ptype );
59+ return df_ptype (x , true );
5860
5961 case vctrs_class_data_frame :
60- return df_map (x , & col_ptype );
62+ return df_ptype (x , false );
6163
6264 case vctrs_class_bare_data_frame :
6365 Rf_errorcall (R_NilValue , "Internal error: Bare data frames should be handled by `vec_ptype()`" );
@@ -77,6 +79,24 @@ static SEXP s3_type(SEXP x, struct vctrs_arg* x_arg) {
7779 return vec_slice (x , R_NilValue );
7880}
7981
82+ SEXP df_ptype (SEXP x , bool bare ) {
83+ SEXP row_nms = PROTECT (df_rownames (x ));
84+
85+ SEXP ptype = R_NilValue ;
86+ if (bare ) {
87+ ptype = PROTECT (bare_df_map (x , & col_ptype ));
88+ } else {
89+ ptype = PROTECT (df_map (x , & col_ptype ));
90+ }
91+
92+ if (TYPEOF (row_nms ) == STRSXP ) {
93+ Rf_setAttrib (ptype , R_RowNamesSymbol , vctrs_shared_empty_chr );
94+ }
95+
96+ UNPROTECT (2 );
97+ return ptype ;
98+ }
99+
80100static SEXP vec_ptype_finalise_unspecified (SEXP x );
81101static SEXP vec_ptype_finalise_dispatch (SEXP x );
82102
0 commit comments