Repository navigation
Closes #592 -- allows for incomplete specification of new order in setcolorder - #1792
Conversation
|
@MichaelChirico can't just |
|
@jangorecki that seems reasonable. Approach in this PR represents a more general new feature, but as you point out, may be tougher to merge into current paradigm. If people actually ask for that, may be worth revisiting. Given that issue has little apparent traffic, your suggestion probably covers vast majority of empirical use cases. Will edit this PR and resubmit. |
Current coverage is 90.21% (diff: 100%)@@ master #1792 diff @@
==========================================
Files 58 58
Lines 11141 11147 +6
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 10048 10056 +8
+ Misses 1093 1091 -2
Partials 0 0
|
There was a problem hiding this comment.
this should be OK this is already after setcolorder above 👍c,a,b isn't it?
There was a problem hiding this comment.
would be nice to have tests and example for vector neworder, eventually handling NAs or duplicates (setdiff will filter out duplicates).
There was a problem hiding this comment.
I'll just change one of the tests to be length>1. the other tests are good but I guess aren't new to this PR...
There was a problem hiding this comment.
yeah, but your chunk changes behavior of the next chunk, should be fine as we still check on setdiff will remove duplicates so later validation will not raise error when it should.names(x)
There was a problem hiding this comment.
Actually setcolorder(DT, c(2, 2, 3)) (e.g.) causes erroneous behavior. But there's a simple fix. Will push momentarily. Thanks for the extra eyes.
…matically amend tests/implementation per jan
There was a problem hiding this comment.
This provides the ability, but what if a user meant to reorder all columns, but accidentally didn't provide enough columns? That's a nice error currently which catches the mistake. This PR would lose that check, iiuc.
I'm thinking a new function setcolfirst() would be clearer. That way when reading the code, we see what the writer intended more easily.
DT = data.table(a=1:3, b=4:6, c=7:9)
DT
a b c
1: 1 4 7
2: 2 5 8
3: 3 6 9
setcolorder(DT,"b")
Error in setcolorder(DT, "b") : neworder is length 1 but x has 3 columns.
That error message could change to :
Error in setcolorder(DT, "b") : neworder is length 1 but x has 3 columns. Consider setcolfirst(DT, "b") instead.
|
@mattdowle why not just new argument then? we used to not create new functions for new stuff if it is not really needed, |
|
Maybe new argument. Looking more into it, what happened to my original request of not just moving to the beginning but moving a column to a particular position? The title of #592 (that I filed on R-Forge in 2013, so I remember wanting the ability for some reason at the time) is "Add new movecol(DT, "colname", 1) ". This PR doesn't close that request because it always moves to the beginning. |
|
That was how I originally programmed it, as a new argument to Problem with that PR was that I used new argument names which made more sense for the more robust version of |
|
I see now - yes comparison to |
|
Given the analogy/parallel use, perhaps we should change the Again this gets at the breaking change issue. But perhaps we can continue to accept (as it stands, the current argument is already |
|
Sounds reasonable to me. So it would be |
|
Actually Jan said it broke some of his own code to have different argument names! Since he called I do like the consistency with |
|
Sorry, I missed that part of PR. |
|
Merging as-is. Thought process ... |
Basic idea is simple -- if
setcolordergets its new 3rd argument, manipulate that into something that the oldsetcolorderwould have understood and continue.