I ran into an error with some analysis code that calls purrr::map_dfr, which I think traces back to dplyr::bind_rows and how it handles numeric and complex types.
Essentially, whereas rbind() and c() are happy to promote numeric to complex when combining, this functionality isn't present in dplyr::bind_rows():
aa <- data.frame(x = 1:2, y = rnorm(2))
bb <- data.frame(x = 3:4, y = complex(real = rnorm(2), imaginary = rnorm(2)))
rbind(aa, bb)
#> x y
#> 1 1 1.588500+0.000000i
#> 2 2 1.989172+0.000000i
#> 3 3 -0.703329+1.683182i
#> 4 4 0.712640-1.207516i
dplyr::bind_rows(aa, bb)
#> Error: Column `y` can't be converted from numeric to complex
Created on 2019-11-13 by the reprex package (v0.3.0)
I see mention of similar functionality described in #3483 re: promoting integers to real.
I realize this may be a low-priority issue. I'd be happy to do dig in and create a PR (not immediately, but perhaps in a few weeks), if that's amenable.
With the vctrs:: based implementation in 0.9.*, we currently get another message:
library(vctrs)
library(dplyr, warn.conflicts = FALSE)
aa <- data.frame(x = 1:2, y = rnorm(2))
bb <- data.frame(x = 3:4, y = complex(real = rnorm(2), imaginary = rnorm(2)))
rbind(aa, bb)
#> x y
#> 1 1 0.2146467+0.0000000i
#> 2 2 -0.4889400+0.0000000i
#> 3 3 0.1621321+0.5435955i
#> 4 4 -1.5431439+1.5787172i
dplyr::bind_rows(aa, bb)
#> Error: No common type for `..1$y` <double> and `..2$y` <complex>.
Coming from vctrs::vec_c() :
vctrs::vec_c(aa$y, bb$y)
#> Error: No common type for `..1` <double> and `..2` <complex>.
Great! I didn't even know that was happening, but glad this is getting included. 馃帀 馃
A similar issue is happening when using bind_rows() with a column of periods on dplyr_0.8.99.9000:
test <- list()
test$a <- data.frame(a = rep(lubridate::now(), 10), p = rep(lubridate::hm("0:30"), 10))
test$b <- data.frame(a = rep(lubridate::now(), 10), p = rep(lubridate::hm("0:50"), 10))
dplyr::bind_rows(test)
#> Error: No common type for `a$p` <Period> and `b$p` <Period>.
Created on 2019-12-01 by the reprex package (v0.2.1)
@yogat3ch this is a vctrs issue, can you open an issue here with this reprex:
library(vctrs)
vec_c(
rep(lubridate::hm("0:30"), 10),
rep(lubridate::hm("0:50"), 10)
)
#> Error: No common type for `..1` <Period> and `..2` <Period>.
Created on 2019-12-02 by the reprex package (v0.3.0.9000)
Closing since this has been fixed in vctrs
Most helpful comment
Closing since this has been fixed in vctrs