Eddi, At the least, I think the documentation needs to be clearer on the use of
"with=FALSE". It does feel inconsistent with the fact that "j" with a single
column should return a vector. In data.frames, the type in "j" being column
names, if it's just one column name, would return a vector, unless drop =
FALSE. That is, DF[, "y"] will return a vector while DF[, c("x", "y")] will
return a data.frame. So, it is inconsistent with data.frame here, I think.
Arun
On Thursday, November 14, 2013 at 5:25 PM, Eduard Antonyan wrote:
> DT[, y] returning a vector is I think the only correct behavior, given the
> understanding of j-expression as something evaluated in the DT environment.
> If they want a data.table they should simply use DT[, list(y)] or DT[,
> data.table(y)].
>
> I haven't thought about DT[, "y", with = FALSE] before as I pretty much never
> use that form, but I see an argument for it staying as is, because "y" and
> c("y") are the same and since we all presumably agree that DT[, c("y", "z"),
> with = FALSE] should return a data.table. If DT[, c("y"), with = FALSE]
> returned a different type that would mean inconsistent return types which
> makes life much harder for users (as evidenced by the periodic drop=FALSE
> questions that come up on SO).
>
> Going back to DT[, y], note that y and list(y) actually produce *different*
> results (in e.g. base_env), so there is no type consistency issue there
> between DT[, y] and DT[, list(y, z)].
>
>
> On Thu, Nov 14, 2013 at 6:09 AM, Arunkumar Srinivasan <[email protected]
> (mailto:[email protected])> wrote:
> > Hi everybody,
> >
> > It'd be nice if you could weigh-in on the bug report filed by Bill here:
> > https://r-forge.r-project.org/tracker/index.php?func=detail&aid=5100&group_id=240&atid=975
> >
> > The gist of it is:
> >
> > require(data.table)
> > DT <- data.table(x=1:5, y=6:10, z=11:15)
> > DT[, y] # returns a vector
> > DT[, "y", with=FALSE] # returns a data.table
> >
> > The question from the bug report basically is: "why is that in the first
> > case, 'j' has only one column and we get a vector, but in the second case,
> > we get a data.table?"
> >
> > My question is: Is this behaviour okay or do you prefer that the first one
> > returns a data.table as well or the second one (with "with=FALSE") returns
> > a vector?
> >
> > Thank you,
> > Arun
> >
> >
> > _______________________________________________
> > datatable-help mailing list
> > [email protected]
> > (mailto:[email protected])
> > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help