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

An attributes_to_columns() function #1585

Open
steveharoz opened this issue Jun 18, 2024 · 1 comment
Open

An attributes_to_columns() function #1585

steveharoz opened this issue Jun 18, 2024 · 1 comment

Comments

@steveharoz
Copy link

steveharoz commented Jun 18, 2024

There are some differences in opinion about what information should go in a data frame vs appear as attributes. An issue with attributes is that accessing a tibble's attributes and its data often requires breaking a piped statement. An example of such a conflict is with emmeans - https://rvlenth.github.io/emmeans/reference/untidy.html

It's much easier to implement a workaround rather than unify everyone's opinion. So I'd like to propose an attributes_to_columns() function. It would add each of a tibble's attribute as a column.

Here is a rough early implementation.

Simple issues I've solved (but I'm still open to suggestions):

  • Ignore common attributes that don't need to be columns like "class" and "names"
  • Handle "row.names" as a special case and call rownames_to_column()
  • Automatically rename conflicting names. A parameter can disable it.

Bigger questions:

  • If an attribute vector has 1 or nrow values, it's simple. But what if a vector has any other number of values?
  • What about values that aren't a vector? Like a data frame or nested list or S3 object? One option here is to just skip it and warn about any attributes that were skipped.

Is this something the tibble maintainers would be interested in? If so, I can flesh out and polish the gist more to make into a proper PR.

@krlmlr
Copy link
Member

krlmlr commented Jun 18, 2024

Thanks. I'm not sure if tibble is the right venue, can we prototype elsewhere and decide based on that?

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

No branches or pull requests

2 participants