diff --git a/ChangeLog b/ChangeLog index 29d06a2cd..e1fa3d417 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2022-10-06 Dirk Eddelbuettel + + * DESCRIPTION (Version, Date): Roll minor version + * inst/include/Rcpp/config.h (RCPP_DEV_VERSION): Idem + + * inst/tinytest/test_dataframe.R (test.DataFrame.PushZeroLength): Add + new test + * inst/tinytest/cpp/DataFrame.cpp (DataFrame_PushOnEmpty): C++ + support for new test + +2022-10-04 Dirk Eddelbuettel + + * inst/include/Rcpp/DataFrame.h (set_type_after_push): Allow zero-row + data.frame objects to be grown by push_{back,front}() + 2022-09-25 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Roll minor version diff --git a/DESCRIPTION b/DESCRIPTION index ca9417b30..b144e3491 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: Rcpp Title: Seamless R and C++ Integration -Version: 1.0.9.3 -Date: 2022-09-25 +Version: 1.0.9.4 +Date: 2022-10-06 Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou, Nathan Russell, Inaki Ucar, Douglas Bates and John Chambers Maintainer: Dirk Eddelbuettel diff --git a/inst/include/Rcpp/DataFrame.h b/inst/include/Rcpp/DataFrame.h index d6db2408d..b76facf72 100644 --- a/inst/include/Rcpp/DataFrame.h +++ b/inst/include/Rcpp/DataFrame.h @@ -140,10 +140,12 @@ namespace Rcpp{ max_rows = Rf_xlength(*it); } } - for (it = Parent::begin(); it != Parent::end(); ++it) { - if (Rf_xlength(*it) == 0 || ( Rf_xlength(*it) > 1 && max_rows % Rf_xlength(*it) != 0 )) { - // We have a column that is not an integer fraction of the largest - invalid_column_size = true; + if (max_rows > 0) { + for (it = Parent::begin(); it != Parent::end(); ++it) { + if (Rf_xlength(*it) == 0 || ( Rf_xlength(*it) > 1 && max_rows % Rf_xlength(*it) != 0 )) { + // We have a column that is not an integer fraction of the largest + invalid_column_size = true; + } } } if (invalid_column_size) { diff --git a/inst/include/Rcpp/config.h b/inst/include/Rcpp/config.h index dc665779b..ecf8b2701 100644 --- a/inst/include/Rcpp/config.h +++ b/inst/include/Rcpp/config.h @@ -30,7 +30,7 @@ #define RCPP_VERSION_STRING "1.0.9" // the current source snapshot (using four components, if a fifth is used in DESCRIPTION we ignore it) -#define RCPP_DEV_VERSION RcppDevVersion(1,0,9,3) -#define RCPP_DEV_VERSION_STRING "1.0.9.3" +#define RCPP_DEV_VERSION RcppDevVersion(1,0,9,4) +#define RCPP_DEV_VERSION_STRING "1.0.9.4" #endif diff --git a/inst/tinytest/cpp/DataFrame.cpp b/inst/tinytest/cpp/DataFrame.cpp index ef48e2572..fff7e4d96 100644 --- a/inst/tinytest/cpp/DataFrame.cpp +++ b/inst/tinytest/cpp/DataFrame.cpp @@ -192,3 +192,17 @@ DataFrame DataFrame_PushZeroLength(){ df1.push_back(v); return df1; } + +// issue #1232 +// [[Rcpp::export]] +Rcpp::DataFrame DataFrame_PushOnEmpty() { + int n = 0; + Rcpp::IntegerVector foo(n); + Rcpp::CharacterVector bar(n); + Rcpp::CharacterVector baz(n); + + Rcpp::List ll = Rcpp::List::create(Rcpp::Named("foo") = foo, + Rcpp::Named("bar") = bar); + ll.push_back(baz, "baz"); + return Rcpp::DataFrame(ll); +} diff --git a/inst/tinytest/test_dataframe.R b/inst/tinytest/test_dataframe.R index a2cc420da..f9571cb1e 100644 --- a/inst/tinytest/test_dataframe.R +++ b/inst/tinytest/test_dataframe.R @@ -113,3 +113,7 @@ expect_equal( DataFrame_PushReplicateLength(), df ) # test.DataFrame.PushZeroLength <- function(){ expect_warning( DataFrame_PushZeroLength()) + +## issue #1232: push on empty data.frame +df <- DataFrame_PushOnEmpty() +expect_equal(ncol(df), 3L)