Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind_rows() reorders 0 column data.frames to the bottom #2175

Closed
StevenMMortimer opened this issue Oct 14, 2016 · 3 comments
Closed

bind_rows() reorders 0 column data.frames to the bottom #2175

StevenMMortimer opened this issue Oct 14, 2016 · 3 comments
Assignees
Labels
Milestone

Comments

@StevenMMortimer
Copy link
Contributor

@StevenMMortimer StevenMMortimer commented Oct 14, 2016

bind_rows() will accept a 1x0 dimensional data.frame, but it creates the all missing row at the bottom, not in the order provided to bind_rows. It seems that the data.frames should be bound in the order specified by the user.

# create data frame with 0 columns and 1 row
dat1 <- data.frame(t(character(0)))
dat2 <- data.frame(a=c('Row2','Row3'))
bind_rows(dat1, dat2)
     a
1 Row2
2 Row3
3 <NA>
> devtools::session_info()
Session info ------------------------------------------------------------
 setting  value                       
 version  R version 3.2.2 (2015-08-14)
 system   x86_64, mingw32             
 ui       RStudio (0.99.441)          
 language (EN)                        
 collate  English_United States.1252  
 tz       America/New_York            
 date     2016-10-14                  

Packages ------------------------------------------------------------
 package    * version date       source        
 assertthat   0.1     2013-12-06 CRAN (R 3.2.2)
 DBI          0.5-1   2016-09-10 CRAN (R 3.2.5)
 devtools     1.12.0  2016-06-24 CRAN (R 3.2.5)
 digest       0.6.10  2016-08-02 CRAN (R 3.2.5)
 dplyr      * 0.5.0   2016-06-24 CRAN (R 3.2.5)
 httr         1.2.1   2016-07-03 CRAN (R 3.2.5)
 magrittr     1.5     2014-11-22 CRAN (R 3.2.2)
 memoise      1.0.0   2016-01-29 CRAN (R 3.2.5)
 R6           2.2.0   2016-10-05 CRAN (R 3.2.5)
 Rcpp         0.12.7  2016-09-05 CRAN (R 3.2.5)
 tibble       1.1     2016-07-04 CRAN (R 3.2.5)
 withr        1.0.2   2016-06-20 CRAN (R 3.2.5)
@krlmlr
Copy link
Member

@krlmlr krlmlr commented Nov 7, 2016

Thanks, confirmed. Would you like to contribute a testthat test?

@StevenMMortimer
Copy link
Contributor Author

@StevenMMortimer StevenMMortimer commented Nov 7, 2016

Yeah, I'd love to contribute. Am I supposed to make the test failing or passing given the current behavior? Here is what I have:

Proposed (currently failing) test case:

test_that("bind_rows puts data frames in order received even if no columns (#2175)", {

  df2 <- data_frame(x = 2, y = 'b')
  df3 <- data_frame(x = 3, y = 'c')
  df1 <- df2[, 0]

  res <- bind_rows(df1, df2, df3)

  expect_equal(res$x, c(NA, 2, 3))
  expect_equal(res$y, c(NA, 'b', 'c'))

})

@krlmlr
Copy link
Member

@krlmlr krlmlr commented Nov 9, 2016

@mgperry: Would you mind adding the test above to #2245 to avoid conflicts? (Please use double quotes, not single quotes.)

@krlmlr krlmlr self-assigned this Feb 10, 2017
@krlmlr krlmlr added this to the data frame 2 milestone Feb 20, 2017
@krlmlr krlmlr added this to the data frame 2 milestone Feb 20, 2017
@krlmlr krlmlr closed this in #2544 Mar 19, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants