From 56df15305b594c1f0d9a4fc8b8ede3cb89038a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 10 May 2022 14:52:49 +0200 Subject: [PATCH] Allow passing number of rows from outside --- inst/include/cpp11/data_frame.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/inst/include/cpp11/data_frame.hpp b/inst/include/cpp11/data_frame.hpp index f1caad51..1848d10a 100644 --- a/inst/include/cpp11/data_frame.hpp +++ b/inst/include/cpp11/data_frame.hpp @@ -66,16 +66,18 @@ class data_frame : public list { namespace writable { class data_frame : public cpp11::data_frame { private: - writable::list set_data_frame_attributes(writable::list&& x) { - x.attr(R_RowNamesSymbol) = {NA_INTEGER, -static_cast(calc_nrow(x))}; + writable::list set_data_frame_attributes(writable::list&& x, int nrow) { + x.attr(R_RowNamesSymbol) = {NA_INTEGER, -nrow}; x.attr(R_ClassSymbol) = "data.frame"; return std::move(x); } public: - data_frame(const SEXP data) : cpp11::data_frame(set_data_frame_attributes(data)) {} + data_frame(const SEXP data) : cpp11::data_frame(set_data_frame_attributes(data, calc_nrow(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) + : cpp11::data_frame(set_data_frame_attributes(data, nrow), is_altrep) {} data_frame(std::initializer_list il) : cpp11::data_frame(set_data_frame_attributes(writable::list(il))) {} data_frame(std::initializer_list il)