[datatable-help] Report an unexpected behavior in data.table 1.5

Matthew Dowle mdowle at mdowle.plus.com
Tue Sep 7 02:57:42 CEST 2010


Branson,

Just fixed this one (bug #1058) and committed. 3 new tests added for
this case (c) including both i=eval(q) and i=eval(parse(text=...)).

Tests for (a) and (b) were already there and all tests pass, so this
change shouldn't undo those or anything else covered by the tests.

Thanks,
Matthew


On Fri, 2010-09-03 at 09:13 +0100, Matthew Dowle wrote:
> Great stuff thanks for the details. That gives me enough to go on. Will
> try to look at the weekend ...
> Matthew
> 
> > Sigh, I gave you some misleading information. I was saying that it
> > doesn't work within function, and work in global. I was wrong. It
> > doesn't work even in global in 1.5.
> >
> >> data.table(A=1:10,B=rnorm(10),key="A")[eval(parse(text="B>0"))]
> > Error in `[.data.table`(data.table(A = 1:10, B = rnorm(10), key = "A"),  :
> >   i has not evaluated to logical, integer or double
> >
> > What I was using eval(...) in global is j expression, i.e.
> > [,eval(...)] rather than i expression [eval(...)]
> > data.table(A=1:10,B=rnorm(10),key="A")[,eval(parse(text="B"))]
> >
> > Apologize for the bothersome information.
> >
> > Best regards,
> >
> > 2010/9/2 Branson Owen <branson.owen at gmail.com>:
> >> Alright, my fault. I was reckless again. I forgot my standard R using
> >> data.table 1.4, and thus the problem doesn't exist. Now, I can give
> >> you the error example with standard R and appropriate data.table
> >> version.
> >>
> >>> fn <- function(criteria)
> >>> data.table(A=1:10,B=rnorm(10),key="A")[eval(parse(text=criteria))]
> >>> fn("B>0")
> >>
> >> [data.table 1.5]
> >>
> >> Error in `[.data.table`(data.table(A = 1:10, B = norm(10), key = "A"),
> >>  :
> >>  i has not evaluated to logical, integer or double
> >>
> >> [data.table 1.4]
> >>    A      B
> >> [1,] 3   0.67
> >> [2,] 4   1.16
> >> [3,] 6   1.01
> >> [4,] 8   0.09
> >>
> >> Again, the solution is to add {} around eval(...)
> >>
> >> ** Discussion of similar problems I have bumped into **
> >> Is it an environment? namespace? or search.path? problem. (Sorry, at
> >> this moment I only have rough impression about these concepts)
> >> Anyway, I have bumped into this kind of problem three times including
> >> this one. Just want to summarize. Might help identify where the
> >> problem is.
> >>
> >> a. DT[J(unique(COL))]
> >> This is the bug Matthew just fixed. [...] can't see function defined
> >> outside. I was using {} wrapper to solve this problem.
> >>
> >> b. DT[...] can't see the local variable defined within a function in
> >> data.table 1.4. This bug is really painful. I have to defined some
> >> variables outside the function. Make it available in global
> >> environment. This bug has been fixed in 1.5 before I can report it.
> >>
> >> c. the bug I reported in the beginning
> >>
> >> The first two bugs belongs to data.table 1.4, and were fixed in
> >> current version 1.5. Bug (c) doesn't exist in 1.4. Thus, I suspect
> >> that fixing the (a) and (b) bugs caused the new bug (c)?
> >>
> >> Please take your time to look at it if you are interested. This bug is
> >> really a minor issue compared to bug (b), which I am glad has been
> >> fixed.
> >>
> >> Best regards,
> >>
> >> 2010/9/2 Branson Owen <branson.owen at gmail.com>:
> >>> Ha, I found the problem is caused by the special REvolution R 3.1.1
> >>> when I tried to re-produce the error. The underlying R is 2.9.2 which
> >>> is not allowed for data.table 1.5 (I rebuild the package to remove the
> >>> version restriction). Sorry, I didn't check it on standard R first
> >>> (Usually, I do.) An embarrassing mistake. :-P I know my working
> >>> environment is dangerous, and I will upgrade to their new version 4.0
> >>> soon, which is build on R-2.11.1. It was lucky that putting a {}
> >>> wrapper can solve my problem.
> >>>
> >>> Best regards,
> >>>
> >>> 2010/8/31 Matthew Dowle <mdowle at mdowle.plus.com>:
> >>>> I just have 30 seconds for quick reply ... can see I'll need
> >>>> reproducible example for this one please; it will probably depend on
> >>>> contents of 'criteria', columns of DT and arguments of the function
> >>>> within which it fails. With that I can take a look later ... Thanks.
> >>>> On Tue, 2010-08-31 at 08:40 -0500, Branson Owen wrote:
> >>>>> Dear all,
> >>>>> I just updated my data.table package from 1.4 to 1.5 yesterday. Ran
> >>>>> into a small problem that has been solved. Just want to report it
> >>>>> since I don't quite understand it.
> >>>>> > DT[eval(parse(text = criteria))]
> >>>>> This command is working in 1.4, but not everywhere in 1.5. It show
> >>>>> this error message when called within a function.
> >>>>> Error in `[.data.table`(Data, eval(parse(text = criteria))) :
> >>>>>   i has not evaluated to logical, integer or double
> >>>>> However, it works in global environment? My solution for a function
> >>>>> call is, again, wrap it with {}. Therefore,
> >>>>>
> >>>>> > DT[ { eval(parse(text = criteria)) } ]
> >>>>>
> >>>>> solved my new problem.
> >>>>>
> >>>>> It didn't behave like this in 1.4. I guess this is because of the
> >>>>> favor Matthew did for me for the DT[ { CJ } ] bug. If nothing can be
> >>>>> perfect, I pretty much like the current setup. There wasn't many
> >>>>> eval(), but there are lots of CJ/J in my codes.
> >>>>>
> >>>>> Just thought you will be interested. Thank you very much for your
> >>>>> efforts and great work.
> >>>>>
> >>>>> Best regards,
> >>>
> >>
> >
> 
> 
> _______________________________________________
> 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