Skip to content

Implement .name_spec = "inner" #1995

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

Open
wants to merge 1 commit into
base: origin-feature/list-unchop-na
Choose a base branch
from

Conversation

DavisVaughan
Copy link
Member

@DavisVaughan DavisVaughan commented Aug 1, 2025

Closes #1988
Branched from #1994

To ignore outer names (but use them in error messages), and retain inner names, see #1988 for rationale

Pretty easy implementation for this, and I'm very satisfied that this can function as a .name_spec that works for the fallback case as well. None of the others do, which can be a little frustrating sometimes when designing fully generic APIs.


There's only one thing to note. In vec_rbind() we previously disallowed this:

vec_rbind(foo = data.frame(x = 1, row.names = "row"), .names_to = "id", .name_spec = zap())

i.e. when you set .names_to = "id" to consume the foo outer name and promote it to a column name, you can't also zap() the row names, which is supposed to zap both the outer and inner parts of the row names.

I think this is overly restrictive? I think we should just say ".name_spec only receives an outer name when .names_to = NULL, otherwise the outer name is consumed by the .names_to behavior". We don't have to restrict the behavior of .name_spec at all, and it is a little annoying that we do so right now.

You should be able to do the rbind call above. It's requesting:

  • Promote the outer foo name to an element of a new id column
  • Zap the inner "row" row name

I think this is a totally valid use case.

Similarly we are now going to allow all of these valid cases:

# Zap `foo`, retain inner row names
vec_rbind(foo = data.frame(x = 1, row.names = "row"), .names_to = zap(), .name_spec = "inner")
# Promote `foo` to `id` column, retain inner row names
vec_rbind(foo = data.frame(x = 1, row.names = "row"), .names_to = "id", .name_spec = "inner")
# Let `.name_spec` handle `foo`, then `.name_spec` retains only inner row names
vec_rbind(foo = data.frame(x = 1, row.names = "row"), .names_to = NULL, .name_spec = "inner")

To ignore outer names (but use them in error messages), and retain inner names
@DavisVaughan DavisVaughan force-pushed the origin-feature/name-spec-inner branch from 7656539 to 733a9a0 Compare August 5, 2025 18:44
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 this pull request may close these issues.

1 participant