tibble icon indicating copy to clipboard operation
tibble copied to clipboard

add_case/add_row silently converts factors to strings

Open vorpalvorpal opened this issue 2 years ago • 1 comments

If you provide a character vector to a column that is currently a factor add_case changes the column class to character.

tibble(col = fct(NA_character_, levels = c("A", "B"))) |>
    add_case(col = "A")

I feel like this should, at the very least, produce a warning rather than just silently changing the class of the column. Possibly it should even change "A" to to fct("A") with a warning.

vorpalvorpal avatar May 25 '23 06:05 vorpalvorpal

Thanks. The underlying function is vctrs::vec_rbind(), this behavior is consistent with vctrs principles.

krlmlr avatar Mar 18 '25 10:03 krlmlr