Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coalesce to follow coercion rules? #2254

Closed
rgknight opened this issue Nov 16, 2016 · 2 comments
Closed

coalesce to follow coercion rules? #2254

rgknight opened this issue Nov 16, 2016 · 2 comments
Labels
bug an unexpected problem or unintended behavior vctrs ↗️

Comments

@rgknight
Copy link

coalesce doesn't coerce an integer to a double

coalesce(as.integer(1), 0)

The conversation rules here seem to suggest that integer to double should be allowable? r-lib/vctrs#7

bind_rows does coerce integers to doubles, which is what initially confused me about which coercions allowed.

df1 <- data.frame(a = as.integer(1))
df2 <- data.frame(a = 0)
tmp <- bind_rows(df1, df2)
class(tmp$a)

coalesce also doesn't follow the factor conversion rules outlined at the link

# Factor + Character doesn't work
a <- c("first", "second", NA) %>% as.factor()
b <- "third"
coalesce(a, b)
# The warning message is also confusing here: Error: Vector 1 has type 'character' not 'integer'

# Factor + factor with different levels returns a warning but doesn't do anything
b <- as.factor(b)
coalesce(a, b)
@krlmlr krlmlr added the bug an unexpected problem or unintended behavior label Nov 22, 2016
@krlmlr
Copy link
Member

krlmlr commented Nov 22, 2016

Thanks, confirmed. We should be more consistent here.

@hadley
Copy link
Member

hadley commented Feb 22, 2017

This will be implemented in vctrs, not dplyr.

@hadley hadley closed this as completed Feb 22, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior vctrs ↗️
Projects
None yet
Development

No branches or pull requests

3 participants