tidyverse / dplyr

dplyr: A grammar of data manipulation
https://dplyr.tidyverse.org/
Other
4.77k stars 2.12k forks source link

bind_rows should lighten up #3483

Closed hadley closed 5 years ago

hadley commented 6 years ago

And work more like readr::read_csv() and friends; i.e. it should always return, providing a data frame or problems if needed.

Robinlovelace commented 6 years ago

Just wondering: is this related to https://github.com/r-spatial/sf/issues/49 ?

Reproducible example that shows expected behaviour. My understanding is that changes are needed on the dplyr side to allow bind_rows.sf similar to *_join.sf functions: https://github.com/r-spatial/sf/blob/master/R/join.R

Reprex:

library(sf)
#> Linking to GEOS 3.5.1, GDAL 2.2.2, proj.4 4.9.2
suppressPackageStartupMessages(library(tidyverse))
nc = read_sf(system.file("shape/nc.shp", package = "sf"))
r1 = rbind(nc[1, ], nc[2, ])
r2 = bind_rows(nc[1, ], nc[2, ])
#> Warning in bind_rows_(x, .id): Vectorizing 'sfc_MULTIPOLYGON' elements may
#> not preserve their attributes

#> Warning in bind_rows_(x, .id): Vectorizing 'sfc_MULTIPOLYGON' elements may
#> not preserve their attributes
class(r2)
#> [1] "sf"         "tbl_df"     "tbl"        "data.frame"
# unclass(r2) # what's in it (all necessary elements it seems - lots)
r2
#> Error in .subset2(x, i): attempt to select less than one element in get1index
Session info ``` r devtools::session_info() #> Session info ------------------------------------------------------------- #> setting value #> version R version 3.4.4 (2018-03-15) #> system x86_64, linux-gnu #> ui X11 #> language en_GB:en #> collate en_GB.UTF-8 #> tz Europe/London #> date 2018-04-10 #> Packages ----------------------------------------------------------------- #> package * version date source #> assertthat 0.2.0 2017-04-11 cran (@0.2.0) #> backports 1.1.2 2017-12-13 CRAN (R 3.4.3) #> base * 3.4.4 2018-03-16 local #> bindr 0.1.1 2018-03-13 CRAN (R 3.4.4) #> bindrcpp 0.2.2 2018-03-29 CRAN (R 3.4.4) #> broom 0.4.4 2018-03-29 CRAN (R 3.4.4) #> cellranger 1.1.0 2016-07-27 cran (@1.1.0) #> class 7.3-14 2015-08-30 CRAN (R 3.4.0) #> classInt 0.1-24 2017-04-16 cran (@0.1-24) #> cli 1.0.0 2017-11-05 CRAN (R 3.4.2) #> colorspace 1.3-2 2016-12-14 CRAN (R 3.4.1) #> compiler 3.4.4 2018-03-16 local #> crayon 1.3.4 2018-02-21 Github (r-lib/crayon@95b3eae) #> datasets * 3.4.4 2018-03-16 local #> DBI 0.8 2018-03-02 cran (@0.8) #> devtools 1.13.5 2018-02-18 CRAN (R 3.4.4) #> digest 0.6.15 2018-01-28 CRAN (R 3.4.3) #> dplyr * 0.7.4 2017-09-28 CRAN (R 3.4.3) #> e1071 1.6-8 2017-02-02 cran (@1.6-8) #> evaluate 0.10.1 2017-06-24 CRAN (R 3.4.1) #> forcats * 0.3.0 2018-02-19 CRAN (R 3.4.4) #> foreign 0.8-69 2017-06-21 CRAN (R 3.4.0) #> formatR 1.5 2017-04-25 CRAN (R 3.4.1) #> ggplot2 * 2.2.1.9000 2018-04-07 Github (tidyverse/ggplot2@3c9c504) #> glue 1.2.0 2017-10-29 CRAN (R 3.4.2) #> graphics * 3.4.4 2018-03-16 local #> grDevices * 3.4.4 2018-03-16 local #> grid 3.4.4 2018-03-16 local #> gtable 0.2.0 2016-02-26 CRAN (R 3.3.2) #> haven 1.1.1 2018-01-18 CRAN (R 3.4.3) #> hms 0.4.2 2018-03-10 CRAN (R 3.4.4) #> htmltools 0.3.6 2017-04-28 cran (@0.3.6) #> httr 1.3.1 2017-08-20 cran (@1.3.1) #> jsonlite 1.5 2017-06-01 cran (@1.5) #> knitr 1.20 2018-02-20 cran (@1.20) #> lattice 0.20-35 2017-03-25 CRAN (R 3.3.3) #> lazyeval 0.2.1 2017-10-29 cran (@0.2.1) #> lubridate 1.7.3 2018-02-27 cran (@1.7.3) #> magrittr 1.5 2014-11-22 CRAN (R 3.3.2) #> memoise 1.1.0 2017-04-21 CRAN (R 3.4.1) #> methods * 3.4.4 2018-03-16 local #> mnormt 1.5-5 2016-10-15 CRAN (R 3.3.2) #> modelr 0.1.1 2017-07-24 cran (@0.1.1) #> munsell 0.4.3 2016-02-13 CRAN (R 3.3.2) #> nlme 3.1-131.1 2018-02-16 CRAN (R 3.4.3) #> parallel 3.4.4 2018-03-16 local #> pillar 1.2.1 2018-02-27 CRAN (R 3.4.4) #> pkgconfig 2.0.1 2017-03-21 cran (@2.0.1) #> plyr 1.8.4 2016-06-08 CRAN (R 3.3.2) #> psych 1.8.3.3 2018-03-30 CRAN (R 3.4.4) #> purrr * 0.2.4 2017-10-18 CRAN (R 3.4.2) #> R6 2.2.2 2017-06-17 cran (@2.2.2) #> Rcpp 0.12.16 2018-03-13 CRAN (R 3.4.4) #> readr * 1.1.1 2017-05-16 cran (@1.1.1) #> readxl 1.0.0 2017-04-18 cran (@1.0.0) #> reshape2 1.4.3 2017-12-11 CRAN (R 3.4.3) #> rlang 0.2.0.9001 2018-04-10 Github (r-lib/rlang@70d2d40) #> rmarkdown 1.9 2018-03-01 CRAN (R 3.4.4) #> rprojroot 1.3-2 2018-01-03 CRAN (R 3.4.3) #> rstudioapi 0.7 2017-09-07 CRAN (R 3.4.1) #> rvest 0.3.2 2016-06-17 CRAN (R 3.3.2) #> scales 0.5.0.9000 2017-11-06 Github (hadley/scales@d767915) #> sf * 0.6-2 2018-04-09 Github (r-spatial/sf@b7de234) #> stats * 3.4.4 2018-03-16 local #> stringi 1.1.7 2018-03-12 CRAN (R 3.4.4) #> stringr * 1.3.0 2018-02-19 cran (@1.3.0) #> tibble * 1.4.2 2018-01-22 cran (@1.4.2) #> tidyr * 0.8.0 2018-01-29 CRAN (R 3.4.3) #> tidyverse * 1.2.1 2017-11-14 CRAN (R 3.4.2) #> tools 3.4.4 2018-03-16 local #> udunits2 0.13 2016-11-17 cran (@0.13) #> units 0.5-1 2018-01-08 cran (@0.5-1) #> utils * 3.4.4 2018-03-16 local #> withr 2.1.2 2018-04-07 Github (jimhester/withr@79d7b0d) #> xml2 1.2.0 2018-01-24 CRAN (R 3.4.3) #> yaml 2.1.18 2018-03-08 CRAN (R 3.4.4) ```

Apologies if this is unrelated, will happily create a separate issue if that's more useful but this seemed related.

billdenney commented 6 years ago

A few specific use cases here are:

And, more use cases are documented in #2584

billdenney commented 6 years ago

If #3552 is superseded by this, please add the more informative error reporting as a feature request here.

hadley commented 5 years ago

bind_rows() should follow the principles in vctrs so there's no need for a separate issue.

lock[bot] commented 4 years ago

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/