Edit: Simply use rbind from base!
I have a list of tibbles with the same column names and orders, but possibly incompatible column types. I would like to vertically-concatenate the tables into one, à la tibble::add_row(), automatically converting types to the greatest common denominator where necessary (in the same way that e.g., c(1, 2, "a") returns c("1", "2", "a"). I don’t know the types of columns in advance.
For example,
> X = tibble(a = 1:3, b = c("a", "b", "c"))
# A tibble: 3 × 2
a b
<int> <chr>
1 1 a
2 2 b
3 3 c
> Y = tibble(a = "Any", b = 1)
# A tibble: 1 × 2
a b
<chr> <dbl>
1 Any 1
Desired output:
# A tibble: 4 × 2
a b
<chr> <chr>
1 1 a
2 2 b
3 3 c
4 Any 1
Is there a way to do this generically? I’m trying to write code for a package that is agnostic about data frames and tibbles (i.e., it doesn’t convert into one or the other).
Ideally, type promotion should reflect the behaviour of c(...) (NULL < raw < logical < integer < double < complex < character < list < expression) — except for factors, where I’d like to preserve the factor label (whatever its type), not the underlying index.