vctrs
vctrs copied to clipboard
Improve consistency of names handling in prototype functions
-
Consistently return unnamed vectors from
vec_ptype2()
. Record vectors gain anames<-
method to support this. It currently only allows setting names toNULL
, 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 ifvec_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
ory
.
Related issue: https://github.com/r-lib/vctrs/issues/623. vec_cast()
should preserve the names of the input
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.
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.