Skip to content
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

setcolorder could accept a vector of column names of length lower than the number of columns #798

Closed
matthieugomez opened this issue Sep 3, 2014 · 6 comments

Comments

@matthieugomez
Copy link
Contributor

It would be nice if setcolorder could accept argument of length lower than the width of the datatable, so that

setcolorder(DT, "v3")

could by typed instead of

setcolorder( DT, c("v3", names(DT[names(DT) != "v3"])) )

As an outsider point of view, it is also more consistent with the fact that setnames can be used with one name instead of the whole list of names.

@matthieugomez matthieugomez changed the title setcolorders could accept argument of lower length setcolorders could accept just a few column names Sep 3, 2014
@matthieugomez matthieugomez changed the title setcolorders could accept just a few column names setcolorders could accept a vector of column names of length lower than the number of columns Sep 3, 2014
@nigmastar
Copy link

I think that he wants to move col V3 to the first position. It would be
better this way maybe:

setcolorder(df, "V3", 1)

With a third optional parameter (that must have same length of the second
and have no duplicates) giving the position(s) of the column(s)
On 3 Sep 2014 19:41, "eantonya" notifications@github.com wrote:

Can you please explain what exactly your first command is supposed to do?


Reply to this email directly or view it on GitHub
#798 (comment)
.

@eantonya
Copy link
Contributor

eantonya commented Sep 3, 2014

@nigmastar that syntax makes a lot more sense to me than the OP one. Perhaps one can do

setcolorder(df, c('V4', 'V3'), c(1,4))

as a multiple column generalization of your proposal.

@matthieugomez
Copy link
Contributor Author

The third argument would make it even better! I'd still like a default to seq(1:length_of_secon_argument) though - in particular for cases when the length is not a priori known

   setcolorder(DT,names(DT)[str_detect(names(DT),"id" )])

I personally reorder columns when I want specific columns to be in the first positions - for instance, I want to see them more clearly in head() or in some viewer.

@arunsrinivasan arunsrinivasan changed the title setcolorders could accept a vector of column names of length lower than the number of columns setcolorder could accept a vector of column names of length lower than the number of columns Sep 6, 2014
@arunsrinivasan
Copy link
Member

Possible duplicate of #592.

@MichaelChirico
Copy link
Member

In fact my PR #1792 fixes #592 by implementing this issue. Just noticed this...

@mattdowle
Copy link
Member

Yes, solved too thanks to @MichaelChirico 's PR #1762 now merged in v1.10.5.

@mattdowle mattdowle added this to the v1.10.6 milestone Aug 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants