Skip to content

Conversation

hadley
Copy link
Member

@hadley hadley commented Sep 25, 2025

Fixes #1206

@hadley hadley requested a review from DavisVaughan September 25, 2025 13:01
@hadley hadley mentioned this pull request Sep 25, 2025
25 tasks
Copy link
Member

@shikokuchuo shikokuchuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably leave this out for now and fix at vctrs, perhaps by adding an early return here: https://github.com/r-lib/vctrs/blob/ca33f4d5c9afb6e44b5373c8f2b196602b6a67aa/src/names.c#L849
Of course, defer to Davis.

Copy link
Member

@DavisVaughan DavisVaughan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make this change in purrr for now

I am not 100% convinced that vctrs should change at all, because we are currently consistent with names<-, which I do like.

It also kind of makes sense?

  • Clearing names on NULL should be a no-op
  • But making a "named NULL" with character() is probably a user issue most of the time?
`names<-`(NULL, NULL)
#> NULL
vec_set_names(NULL, NULL)
#> NULL

`names<-`(NULL, character())
#> Error: attempt to set an attribute on NULL
vec_set_names(NULL, character())
#> Error in names(x) <- names: attempt to set an attribute on NULL

`names<-`(NULL, "x")
#> Error: attempt to set an attribute on NULL
vec_set_names(NULL, "x")
#> Error in `vec_set_names()`:
#> ! The size of `names`, 1, must be the same as the size of `x`, 0.

Really the main weirdness in this particular case is that list_unchop() returns NULL at all. Technically it should return unspecified(0), which you could set empty names on to make named unspecified(0), but we try not to expose that type much. Regardless, I'm not sure I want to tweak vec_set_names() because of this corner case in list_unchop().

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.

map_vec() fails on empty named lists()

3 participants