Skip to content
Closed
15 changes: 15 additions & 0 deletions r/src/arrow_cpp11.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ cpp11::writable::list to_r_list(const std::vector<std::shared_ptr<T>>& x) {
} // namespace r
} // namespace arrow

struct r_vec_size {
explicit r_vec_size(R_xlen_t x) : value(x) {}

R_xlen_t value;
};

namespace cpp11 {

template <typename T>
Expand All @@ -428,4 +434,13 @@ SEXP as_sexp(const std::shared_ptr<T>& ptr) {
return cpp11::to_r6<T>(ptr);
}

inline SEXP as_sexp(r_vec_size size) {
R_xlen_t x = size.value;
if (x > std::numeric_limits<int>::max()) {
return Rf_ScalarReal(x);
} else {
return Rf_ScalarInteger(x);
}
}

} // namespace cpp11
4 changes: 2 additions & 2 deletions r/src/recordbatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ int RecordBatch__num_columns(const std::shared_ptr<arrow::RecordBatch>& x) {
}

// [[arrow::export]]
int RecordBatch__num_rows(const std::shared_ptr<arrow::RecordBatch>& x) {
return x->num_rows();
r_vec_size RecordBatch__num_rows(const std::shared_ptr<arrow::RecordBatch>& x) {
return r_vec_size(x->num_rows());
}

// [[arrow::export]]
Expand Down
4 changes: 3 additions & 1 deletion r/src/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ int Table__num_columns(const std::shared_ptr<arrow::Table>& x) {
}

// [[arrow::export]]
int Table__num_rows(const std::shared_ptr<arrow::Table>& x) { return x->num_rows(); }
r_vec_size Table__num_rows(const std::shared_ptr<arrow::Table>& x) {
return r_vec_size(x->num_rows());
}

// [[arrow::export]]
std::shared_ptr<arrow::Schema> Table__schema(const std::shared_ptr<arrow::Table>& x) {
Expand Down