-
Notifications
You must be signed in to change notification settings - Fork 66
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
Preserve names when row-binding data frames #924
Conversation
86bf21f
to
066f911
Compare
src/slice-assign.c
Outdated
proxy_nms = PROTECT(chr_assign(proxy_nms, index, value_nms)); | ||
|
||
proxy = PROTECT(r_maybe_duplicate(proxy)); | ||
vec_set_names(proxy, proxy_nms); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vec_set_names()
works like vec_proxy_assign()
. It might have to call back to names<-
and duplicate the input, so it always returns it's input. So you won't need to duplicate the proxy, but I think you do need to do proxy = PROTECT(vec_set_names(proxy, proxy_nms))
@@ -517,3 +517,27 @@ test_that("rbind repairs names of data frames (#704)", { | |||
class = "vctrs_error_names_must_be_unique" | |||
) | |||
}) | |||
|
|||
test_that("rbind supports names and inner names (#689)", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work with S3 objects like factors / POSIXct that vec_set_names()
has to fall back to names<-
on, but could you please add a test for that too? It would make me feel a bit better about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would have caught the unassigned return you mentioned above, so that test is definitely needed!
c9519b1
to
9dd2c9e
Compare
9dd2c9e
to
050fb60
Compare
Branched from #923.
Closes #689.
The internal
vec_assign()
function gains anassign_names
parameter. Whentrue
, names are assigned row-recursively.vec_c()
andvec_rbind()
setassign_names
totrue
so that they preserve row names and inner names.