66#include < string> // for string, basic_string
77#include < utility> // for move
88
9- #include " R_ext/Arith.h" // for NA_INTEGER
9+ #include " R_ext/Arith.h" // for NA_INTEGER
10+ #include " Rversion.h"
1011#include " cpp11/R.hpp" // for Rf_xlength, SEXP, SEXPREC, INTEGER
1112#include " cpp11/attribute_proxy.hpp" // for attribute_proxy
1213#include " cpp11/list.hpp" // for list, r_vector<>::r_vector, r_v...
@@ -24,6 +25,7 @@ class data_frame : public list {
2425
2526 friend class writable ::data_frame;
2627
28+ #if R_VERSION < R_Version(4, 6, 0)
2729 /* we cannot use Rf_getAttrib because it has a special case for c(NA, -n) and creates
2830 * the full vector */
2931 static SEXP get_attrib0 (SEXP x, SEXP sym) {
@@ -35,8 +37,10 @@ class data_frame : public list {
3537
3638 return R_NilValue;
3739 }
40+ #endif
3841
3942 static R_xlen_t calc_nrow (SEXP x) {
43+ #if R_VERSION < R_Version(4, 6, 0)
4044 auto nms = get_attrib0 (x, R_RowNamesSymbol);
4145 bool has_short_rownames =
4246 (Rf_isInteger (nms) && Rf_xlength (nms) == 2 && INTEGER (nms)[0 ] == NA_INTEGER);
@@ -47,6 +51,9 @@ class data_frame : public list {
4751 if (!Rf_isNull (nms)) {
4852 return Rf_xlength (nms);
4953 }
54+ #else
55+ if (Rf_isDataFrame (x)) return R_nrow (x);
56+ #endif
5057
5158 if (Rf_xlength (x) == 0 ) {
5259 return 0 ;
0 commit comments