[datatable-help] [J(channel) , ] [J(chan) , ] give different results when chan=channel

Matthew Dowle mdowle at mdowle.plus.com
Thu Nov 8 18:29:08 CET 2012


I see what you mean and agree this doesn't feel comfortable. To address
this, .() was added as a first step in 1.8.2 :

o New DT[.(...)] syntax (in the style of package plyr) is identical to
  DT[list(...)], DT[J(...)] and DT[data.table(...)]. We plan to add
  ..(), too, so that .() and ..() are analogous to the file system's
  ./ and ../; i.e., .() evaluates within the frame of DT and ..() in
  the parent scope.

So in this case instead of

    eso[J(channel)]

it would be

    eso[..(channel)]

and the contents of () would be evaluated in calling scope.

Thought about a new flag to [.data.table, but that might appear far away
on the line of code from i, or even further down on another line.  ..()
like that is right there in i where your eyes are looking at i. Easier to
read.

That was the idea, anyway. Would this work for you?

Easy to remember .() and ..() because it's just like the file system.

Matthew


> I just got bitten by a nasty bug in my code:
>
>
> library(data.table)
> eso = data.table(pH=rnorm(10),channel=1:2,key="channel")
> chan = 1
> channel = chan
>
> eso[J(chan)]    # not a column name, returns what I want
> eso[J(channel)] # channel is a column and key, returns all
>
> From a standpoint of evaluation, it is clear to me what happens, but I
> find
> this behavior highly confusing. I would wish if the latter could
> optionally
> be flagged with a warning, in case this is not "by design".
>
> Dieter
>
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/J-channel-J-chan-give-different-results-when-chan-channel-tp4648911.html
> Sent from the datatable-help mailing list archive at Nabble.com.
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>



More information about the datatable-help mailing list