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

Allow logical specification in .SDcols #1060

Closed
stefanfritsch opened this issue Mar 3, 2015 · 2 comments
Closed

Allow logical specification in .SDcols #1060

stefanfritsch opened this issue Mar 3, 2015 · 2 comments
Assignees
Milestone

Comments

@stefanfritsch
Copy link

Hi,

these are two connected feature requests for .SDcols:

.1. First, allow logical specifications of columns which would allow stuff like this:

DT[,`:=`(colnames(.SD), lapply(.SD,as.character)), .SDcols=sapply(.SD, is.factor)]

Note that this fails currently because

  • colnames(.SD) in the := specification doesn't work as I mentioned in issue names(.SD) := ... should work #795
  • .SD is not accessible in .SDcols. This would mean that there are two definitions of .SD around (one pre- and one post-.SDcols-selection), but imho the difference is rather intuitive.
  • The resulting logical vector doesn't work.

.2. As a second step it would be really cool if .SDcols would accept selection functions, kind of like Filter:

DT[,(.SDcols):=lapply(.SD,as.character), .SDcols=is.factor]

Other possible use cases apart from type-checks would be basic thresholds and the like.

.3. I smuggled a third wish into the last example. .SDcols already looks like one of the comfort-variables, it would be really nice if we could use it to access the available columns. :)

Thanks for having a look at it even if it doesn't get implemented

Ciao,
Stefan

@arunsrinivasan
Copy link
Member

Please file 1 issue per FR/bug, even if they are related. It helps close the issues as and when they are implemented / discussed.

I'll consider point (1) alone for this issue, and will implement .SDcols taking logical argument. Could you please re-file the other issues when you find time? Thanks.

The use of colnames(.SD) in the LHS would be a completely different FR (and I think one already exists) as well.

@stefanfritsch
Copy link
Author

Hi Arun,

thanks a lot for the patch. 👍

I'd consider the colnames(.SD) issue part of #795 as mentioned in the report.

I'll have to think about the functions-as-.SDcols-value thing a bit. I put it in here as an aside because it could be implemented as a quick hack the way you did the logicals (if(is.function) ...) but before I make it its own issue I'd like to find a more flexible and less hacky way; even if it's just a feature request / conversation starter. :)

Ciao,
Stefan

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

2 participants