You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On Sep 12, 2017, at 9:36 AM, Kirill Müller ***@***.***> wrote:
Is the behavior any different with the CRAN version?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
@krlmlr I was just about to post an issue asking for add_column() to be generic.
For packages that extend tibble, like my new tibbletime package, I have to handle the dropping of extra classes and attributes that occurs with most tidyverse functions. Normally I create a tidyverse_fun.tbl_time generic version that drops the classes and attributes that I dont want to lose, calls the function and then adds them back.
Since add_column isn't generic, I can't do that there, and that call to cbind() removes the classes and attributes that I need to keep. At the end of add_column(), the classes are added back, but the attributes are not, which causes a lot of problems!
So for my problem, either add_column would need to be generic or it should also try and add the attributes of the original .data back on. Any help there is definitely welcome!
Most classes that build on top of tbl_df I think already need to define a [ method.... my preference would be to try to minimize the total number of methods that need to be defined in order to extend and build ontop of tbl_df. I think building add_column with [ is one such opportunity.
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.
Activity
krlmlr commentedon Sep 6, 2017
Does
bind_cols()work?t-kalinowski commentedon Sep 6, 2017
Yes (with dev version of dplyr and tibble)
krlmlr commentedon Sep 12, 2017
Is the behavior any different with the CRAN version?
t-kalinowski commentedon Sep 12, 2017
krlmlr commentedon Sep 12, 2017
Closing, we don't currently support
cbind().t-kalinowski commentedon Sep 12, 2017
The issue is about
add_column, notcbind.t-kalinowski commentedon Sep 12, 2017
The problem is caused by the call of cbind here:
tibble/R/add.R
Line 141 in 6320d77
krlmlr commentedon Sep 13, 2017
Bummer. This seems to mean that we need to make
add_column()generic, with an implementation in dplyr.t-kalinowski commentedon Sep 13, 2017
Hmm, seems not ideal.
Would an approach based on
[[<-to add the columns and then[to reorder the columns be simpler?DavisVaughan commentedon Sep 15, 2017
@krlmlr I was just about to post an issue asking for
add_column()to be generic.For packages that extend
tibble, like my newtibbletimepackage, I have to handle the dropping of extra classes and attributes that occurs with most tidyverse functions. Normally I create atidyverse_fun.tbl_timegeneric version that drops the classes and attributes that I dont want to lose, calls the function and then adds them back.Since
add_columnisn't generic, I can't do that there, and that call tocbind()removes the classes and attributes that I need to keep. At the end ofadd_column(), the classes are added back, but the attributes are not, which causes a lot of problems!So for my problem, either
add_columnwould need to be generic or it should also try and add the attributes of the original.databack on. Any help there is definitely welcome!t-kalinowski commentedon Sep 15, 2017
Most classes that build on top of
tbl_dfI think already need to define a[method.... my preference would be to try to minimize the total number of methods that need to be defined in order to extend and build ontop oftbl_df. I think buildingadd_columnwith[is one such opportunity.DavisVaughan commentedon Sep 16, 2017
Solution
I think I have something that fixes everyone's problems using
[.https://github.com/DavisVaughan/tibble/blob/master/R/add.R#L141
Passes all tests for
test-add.R.Fixes t-kalinowski's problem
Details
Fixes my own problem
Classes and attrs are no longer lost.
Classes of the original
.dataare kept.Details
krlmlr commentedon Sep 16, 2017
Thanks, happy to review a PR.
Merge pull request #306 from DavisVaughan/master
krlmlr commentedon Oct 4, 2017
Closed by #306.
Merge tag 'v1.3.4.9002'
Merge tag 'v1.4.1'
github-actions commentedon Dec 12, 2020
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.