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

bind_rows() silently converts factor to character #1485

Closed
jennybc opened this issue Oct 29, 2015 · 9 comments
Closed

bind_rows() silently converts factor to character #1485

jennybc opened this issue Oct 29, 2015 · 9 comments
Assignees
Milestone

Comments

@jennybc
Copy link
Member

jennybc commented Oct 29, 2015

library(dplyr)
class(iris$Species)
#> [1] "factor"
iris2 <- bind_rows(head(iris, 1),
                   tail(iris, 1) %>% mutate(Species = as.character(Species)))
class(iris2$Species)
#> [1] "character"

The joins issue a warning whenever they do this.

@romainfrancois
Copy link
Member

Right. @hadley do we need a warning here ?

@romainfrancois
Copy link
Member

> d1 <- head(iris, 1)
> d2 <- tail(iris, 1) %>% mutate(Species = as.character(Species))
> res <- bind_rows(d1,d2)
> str(res)
Classestbl_df’, ‘tbland 'data.frame':   2 obs. of  5 variables:
 $ Sepal.Length: num  5.1 5.9
 $ Sepal.Width : num  3.5 3
 $ Petal.Length: num  1.4 5.1
 $ Petal.Width : num  0.2 1.8
 $ Species     : chr  "setosa" "virginica"

@hadley
Copy link
Member

hadley commented Oct 30, 2015

Yeah, we should be consistent wherever we do coercion.

@romainfrancois romainfrancois self-assigned this Nov 1, 2015
@romainfrancois romainfrancois added this to the 0.5 milestone Nov 1, 2015
@RichardJActon
Copy link

I think it would be nice to have a 'refactor' option on this function so that you get a new factor with levels from both of the previous data objects instead of a character vector, a choice of what to coerce to as it where.

@batpigandme
Copy link
Contributor

Hi @RichardJActon,

Just a heads up: comments on old, closed issues have pretty low-visibility, and (depending on the package and age of the issue) may not be consistent with current versions.

If this is something you think needs serious reconsideration, please open a new issue that follows the tidyverse guidelines.

Thanks

@RichardJActon
Copy link

Hi @batpigandme Thanks for the heads up,

This is more a suggested feature, the standard format for raising issues seems quite tailored for bug reports, are suggested features welcome via issues?

Thought I'd raise it here in case someone who knew what they were talking about could shoot it down on grounds that would be inconsistent with some standard behaviour in the tidyverse, before I went any further with it.

@batpigandme
Copy link
Contributor

@RichardJActon,
You can certainly submit feature requests— the format should be similar to an issue in the sense that you show the difference between the current behaviour and the desired one.

If you're reopening something for discussion, you should probably address whatever concerns were previously mentioned (speaking abstractly here). I recommend browsing through some of the existing issues with the feature label (here) to get a sense of what the maintainers ask for, etc. — I'd avoid using the ones submitted by the maintainers (e.g. hadley, krlmlr), as they tend not to follow form in the same way.

@RichardJActon
Copy link

Ah, I think I found an existing open issue to which this is applicable: #3278. Thanks for the help @batpigandme.

@lock
Copy link

lock bot commented Aug 27, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Aug 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants