Skip to content

Allow logical specification in .SDcols #1060

@stefanfritsch

Description

@stefanfritsch

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

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions