Skip to content

Commit

Permalink
Use R_xlen_t consistently in data_frame.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Aug 22, 2024
1 parent 54fc431 commit ab48d33
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cpp11test/src/test-data_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ context("data_frame-C++") {
SEXP x = PROTECT(Rf_allocVector(VECSXP, 0));

bool is_altrep = false;
int nrow = 10;
R_xlen_t nrow = 10;

// Manually specify `nrow` using special constructor
cpp11::writable::data_frame df(x, is_altrep, nrow);
Expand Down
10 changes: 5 additions & 5 deletions inst/include/cpp11/data_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class data_frame : public list {
return R_NilValue;
}

static int calc_nrow(SEXP x) {
static R_xlen_t calc_nrow(SEXP x) {
auto nms = get_attrib0(x, R_RowNamesSymbol);
bool has_short_rownames =
(Rf_isInteger(nms) && Rf_xlength(nms) == 2 && INTEGER(nms)[0] == NA_INTEGER);
if (has_short_rownames) {
return abs(INTEGER(nms)[1]);
return static_cast<R_xlen_t>(abs(INTEGER(nms)[1]));
}

if (!Rf_isNull(nms)) {
Expand Down Expand Up @@ -70,8 +70,8 @@ class data_frame : public cpp11::data_frame {
return set_data_frame_attributes(std::move(x), calc_nrow(x));
}

writable::list set_data_frame_attributes(writable::list&& x, int nrow) {
x.attr(R_RowNamesSymbol) = {NA_INTEGER, -nrow};
writable::list set_data_frame_attributes(writable::list&& x, R_xlen_t nrow) {
x.attr(R_RowNamesSymbol) = {NA_INTEGER, -static_cast<int>(nrow)};
x.attr(R_ClassSymbol) = "data.frame";
return std::move(x);
}
Expand All @@ -80,7 +80,7 @@ class data_frame : public cpp11::data_frame {
data_frame(const SEXP data) : cpp11::data_frame(set_data_frame_attributes(data)) {}
data_frame(const SEXP data, bool is_altrep)
: cpp11::data_frame(set_data_frame_attributes(data), is_altrep) {}
data_frame(const SEXP data, bool is_altrep, int nrow)
data_frame(const SEXP data, bool is_altrep, R_xlen_t nrow)
: cpp11::data_frame(set_data_frame_attributes(data, nrow), is_altrep) {}
data_frame(std::initializer_list<list> il)
: cpp11::data_frame(set_data_frame_attributes(writable::list(il))) {}
Expand Down

0 comments on commit ab48d33

Please sign in to comment.