[datatable-help] with=FALSE

Matthew Dowle mdowle at mdowle.plus.com
Thu Apr 26 11:02:33 CEST 2012


Dear Datatablers,

It may be possible for these :

    DT[,1]
    DT[,1:3]
    DT[,c("colA","colB")]

all to return a data.table of those columns, rather than needing
with=FALSE, for convenience. After all, there is no useful purpose of
returning the j vector itself in these cases; the programmers intent is
unambiguous (afaik).

Where a variable holds the vector of column names or numbers, with=FALSE
would still be needed.

    colvars = c("colA","colB")
    DT[,colvars]  # would return the column called colvars if exists, or
the vector itself.
    DT[,colvars,with=FALSE]   # with needed in this case

Given with=FALSE would become optional in the simpler cases, I'm thinking
it would be backwards compatible and wouldn't cause any problems to
existing code. Unless, there is a valid reason to return the j vector
straight back (a special case of a larger idiom perhaps)?

Internally it would look at the j expression to see if it was a single
column position, a call to ":" or a call to "c()", which resulted in a
valid vector of column names or positions. Anything more complicated would
need with=FALSE.  The risk would be inconsistency and confusion, or not
maybe?

This would change the very first FAQ (1.1), though. Not sure if it would
make it easier or harder to make the transition to data.table.

Thoughts?

Matthew




More information about the datatable-help mailing list