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

df_paste preserves factors but drops unseen levels #39

Closed
MilesMcBain opened this issue Mar 18, 2017 · 4 comments · May be fixed by #75
Closed

df_paste preserves factors but drops unseen levels #39

MilesMcBain opened this issue Mar 18, 2017 · 4 comments · May be fixed by #75

Comments

@MilesMcBain
Copy link
Owner

example:

head(iris) %>% df_paste()
data.frame(
   Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5, 5.4),
    Sepal.Width = c(3.5, 3, 3.2, 3.1, 3.6, 3.9),
   Petal.Length = c(1.4, 1.4, 1.3, 1.5, 1.4, 1.7),
    Petal.Width = c(0.2, 0.2, 0.2, 0.2, 0.2, 0.4),
        Species = as.factor(c("setosa", "setosa", "setosa", "setosa", "setosa",
                              "setosa"))
)

Part of me is happy with this since unused factor levels are usually annoying. However this may be unexpected for some people.

@jonocarroll
Copy link
Contributor

If the data is coming from an existing structure then I'd say preserve factor levels. Happy to look into making that happen.

@MilesMcBain
Copy link
Owner Author

I'm unsure about merging this. It has never be raised by a user, this was just me making a note of the behaviour.

One of the primary cases when using data from an existing structure is to create a small subset for an example. If you're subsetting a dataframe to become an example, I presume you probably want the factor levels chopped as well, since if those levels were important for the example you would have been sure to include them. I am guessing this change might result in a few people having to manually fudge the factor levels and that is not what I would want.

If you're taking the whole data frame, there is no issue.

@jonocarroll
Copy link
Contributor

All good. I saw it as a 'see how hard it is to do' sort of thing.

One option is to have it activated with an argument, defaulting to dropping levels. I can update if that's something you'd like to try out.

@MilesMcBain
Copy link
Owner Author

Leaving factor behaviour as-is for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants