Skip to content

Commit b6d25ce

Browse files
authored
Merge pull request #1233 from RcppCore/feature/zero_row_data_frame_push_back
Support zero row data frame push back/front (closes #1232)
2 parents 8bd3754 + 6ff1734 commit b6d25ce

File tree

6 files changed

+43
-8
lines changed

6 files changed

+43
-8
lines changed

ChangeLog

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2022-10-06 Dirk Eddelbuettel <[email protected]>
2+
3+
* DESCRIPTION (Version, Date): Roll minor version
4+
* inst/include/Rcpp/config.h (RCPP_DEV_VERSION): Idem
5+
6+
* inst/tinytest/test_dataframe.R (test.DataFrame.PushZeroLength): Add
7+
new test
8+
* inst/tinytest/cpp/DataFrame.cpp (DataFrame_PushOnEmpty): C++
9+
support for new test
10+
11+
2022-10-04 Dirk Eddelbuettel <[email protected]>
12+
13+
* inst/include/Rcpp/DataFrame.h (set_type_after_push): Allow zero-row
14+
data.frame objects to be grown by push_{back,front}()
15+
116
2022-09-25 Dirk Eddelbuettel <[email protected]>
217

318
* DESCRIPTION (Version, Date): Roll minor version

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: Rcpp
22
Title: Seamless R and C++ Integration
3-
Version: 1.0.9.3
4-
Date: 2022-09-25
3+
Version: 1.0.9.4
4+
Date: 2022-10-06
55
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou,
66
Nathan Russell, Inaki Ucar, Douglas Bates and John Chambers
77
Maintainer: Dirk Eddelbuettel <[email protected]>

inst/include/Rcpp/DataFrame.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,12 @@ namespace Rcpp{
140140
max_rows = Rf_xlength(*it);
141141
}
142142
}
143-
for (it = Parent::begin(); it != Parent::end(); ++it) {
144-
if (Rf_xlength(*it) == 0 || ( Rf_xlength(*it) > 1 && max_rows % Rf_xlength(*it) != 0 )) {
145-
// We have a column that is not an integer fraction of the largest
146-
invalid_column_size = true;
143+
if (max_rows > 0) {
144+
for (it = Parent::begin(); it != Parent::end(); ++it) {
145+
if (Rf_xlength(*it) == 0 || ( Rf_xlength(*it) > 1 && max_rows % Rf_xlength(*it) != 0 )) {
146+
// We have a column that is not an integer fraction of the largest
147+
invalid_column_size = true;
148+
}
147149
}
148150
}
149151
if (invalid_column_size) {

inst/include/Rcpp/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define RCPP_VERSION_STRING "1.0.9"
3131

3232
// the current source snapshot (using four components, if a fifth is used in DESCRIPTION we ignore it)
33-
#define RCPP_DEV_VERSION RcppDevVersion(1,0,9,3)
34-
#define RCPP_DEV_VERSION_STRING "1.0.9.3"
33+
#define RCPP_DEV_VERSION RcppDevVersion(1,0,9,4)
34+
#define RCPP_DEV_VERSION_STRING "1.0.9.4"
3535

3636
#endif

inst/tinytest/cpp/DataFrame.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,17 @@ DataFrame DataFrame_PushZeroLength(){
192192
df1.push_back(v);
193193
return df1;
194194
}
195+
196+
// issue #1232
197+
// [[Rcpp::export]]
198+
Rcpp::DataFrame DataFrame_PushOnEmpty() {
199+
int n = 0;
200+
Rcpp::IntegerVector foo(n);
201+
Rcpp::CharacterVector bar(n);
202+
Rcpp::CharacterVector baz(n);
203+
204+
Rcpp::List ll = Rcpp::List::create(Rcpp::Named("foo") = foo,
205+
Rcpp::Named("bar") = bar);
206+
ll.push_back(baz, "baz");
207+
return Rcpp::DataFrame(ll);
208+
}

inst/tinytest/test_dataframe.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,7 @@ expect_equal( DataFrame_PushReplicateLength(), df )
113113

114114
# test.DataFrame.PushZeroLength <- function(){
115115
expect_warning( DataFrame_PushZeroLength())
116+
117+
## issue #1232: push on empty data.frame
118+
df <- DataFrame_PushOnEmpty()
119+
expect_equal(ncol(df), 3L)

0 commit comments

Comments
 (0)