Skip to content

Commit cf85acd

Browse files
committed
Backport CRAN change from cran/cpp11@6cc2e8b
1 parent c9e0f9b commit cf85acd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

inst/include/cpp11/data_frame.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class data_frame : public list {
2424

2525
friend class writable::data_frame;
2626

27+
#if R_VERSION < R_Version(4,6,0)
2728
/* we cannot use Rf_getAttrib because it has a special case for c(NA, -n) and creates
2829
* the full vector */
2930
static SEXP get_attrib0(SEXP x, SEXP sym) {
@@ -35,8 +36,10 @@ class data_frame : public list {
3536

3637
return R_NilValue;
3738
}
39+
#endif
3840

3941
static R_xlen_t calc_nrow(SEXP x) {
42+
#if R_VERSION < R_Version(4,6,0)
4043
auto nms = get_attrib0(x, R_RowNamesSymbol);
4144
bool has_short_rownames =
4245
(Rf_isInteger(nms) && Rf_xlength(nms) == 2 && INTEGER(nms)[0] == NA_INTEGER);
@@ -47,6 +50,10 @@ class data_frame : public list {
4750
if (!Rf_isNull(nms)) {
4851
return Rf_xlength(nms);
4952
}
53+
#else
54+
if (Rf_isDataFrame(x))
55+
return R_nrow(x);
56+
#endif
5057

5158
if (Rf_xlength(x) == 0) {
5259
return 0;

0 commit comments

Comments
 (0)