vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

Improve consistency of names handling in prototype functions

Open lionel- opened this issue 4 years ago • 3 comments

  • Consistently return unnamed vectors from vec_ptype2(). Record vectors gain a names<- method to support this. It currently only allows setting names to NULL, but should be extended in the future by storing names in a special field.

  • Consistently preserve names in vec_ptype(), including row names. I still wonder if vec_ptype() should unname though.

  • In the same spirit of unnaming the results of ptype2 methods, we also empty them. This simplifies the implementation of methods which can now just return x or y.

lionel- avatar Apr 17 '20 17:04 lionel-

Related issue: https://github.com/r-lib/vctrs/issues/623. vec_cast() should preserve the names of the input

lionel- avatar Apr 20 '20 12:04 lionel-

I am uncomfortable with this change. I don't think it's needed for dplyr 1.0.0, so I'd prefer to put off any discussion until we have more time.

hadley avatar Apr 20 '20 12:04 hadley

Interestingly we have this in vec_is(), which also goes in the direction of removing names from prototypes:

  x <- vec_slice(x, integer())
  ptype <- vec_slice(ptype, integer())

  # FIXME: Remove row names for matrices and arrays, and handle empty
  # but existing dimnames
  x <- vec_set_names(x, NULL)
  ptype <- vec_set_names(ptype, NULL)

Worth noting that rcrd vectors are currently not doing the right thing with this implementation, since vec-set-names currently goes through names<-.vctrs_vctr. This overwrites the field names.

lionel- avatar Apr 20 '20 14:04 lionel-