You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vctrs::vec_c("a", NA) # WORKS
vctrs::vec_c("a", logical(0)) # FAILS
This issue has broken my R prod code more than any other. I would like to understand why.
Usually I have bind_rows combine some dataframes. Sometimes the dataframes have all NA columns that are read-in as logical.
When I bind these dataframes with others that have values in these columns, type conversion works and I don't have a problem. But if it happens that all dataframe rows are deleted before merging, like in a shiny reactive df for instance, then bind_rows fails with message Can't combine ..1<character> and..2 <logical>.
Example:
df_with_na <- tibble(
column = c(NA, NA, NA)
)
# Column is logical
# class(df_with_na$column)))
print(
bind_rows(
df_with_na,
tibble(
column = c("a", "b", "c")
)
)
)
# Binding works, logical made of NAs is combined with character.
# Rows are removed from the df.
df_without_rows <- df_with_na[0,]
print(class(df_without_rows$column))
bind_rows(
df_without_rows,
tibble(
column = c("a", "b", "c")
)
)
Knowing that it happens, I can be proactive and drop all NA columns, or skip binding dataframes with 0 rows. But I'm curious why this behavior happens.
Is it that an all NA vector is a "fake" logical, while logical(0) could be a real logical vector comprised of booleans?
The text was updated successfully, but these errors were encountered:
This issue has broken my R prod code more than any other. I would like to understand why.
Usually I have
bind_rows
combine some dataframes. Sometimes the dataframes have all NA columns that are read-in as logical.When I bind these dataframes with others that have values in these columns, type conversion works and I don't have a problem. But if it happens that all dataframe rows are deleted before merging, like in a shiny reactive df for instance, then
bind_rows
fails with messageCan't combine
..1<character> and
..2<logical>.
Example:
Knowing that it happens, I can be proactive and drop all NA columns, or skip binding dataframes with 0 rows. But I'm curious why this behavior happens.
Is it that an all NA vector is a "fake" logical, while logical(0) could be a real logical vector comprised of booleans?
The text was updated successfully, but these errors were encountered: