[datatable-help] Streamlining unit tests with test_that

Matthew Dowle mdowle at mdowle.plus.com
Tue Dec 7 03:17:37 CET 2010


Been offline for a few days, just catching up with these threads.

Yes - Tom's idea looks good to me. .GlobalEnv would be considered
data.table aware since it isn't a namespace then, thus short-circuiting
the first || when called from the user workspace and retaining the
efficiency fix of the change from cendta to cedta a while back (that the
identical(te,.GlobalEnv) was there for) so I'm happy.

The topenv when the caller is a namespaceless package is .GlobalEnv
rather than the package (if I remember the issue correctly) which is the
reason namespaceless packages are incorrectly considered data.table
aware. As Tom says that's an issue anyway and shouldn't be affected by
this change. In practice it's not an issue since we're not aware of any
namespaceless packages being used by data.table users. Have changed the
priority of that tracker item to low (which oddly on R-Forge is 1 not
5).

The new cedta might well fix this bug neatly too :
https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1131&group_id=240&atid=975

Haven't looked at the test_that proposal yet. Shall I look once these
issues are resolved and a few tests are working ok?

Matthew


On Wed, 2010-12-01 at 15:01 -0500, Tom Short wrote:
> This is more for Matthew's input. Following up on cedta used within
> sys.source'd code, could cedta be changed to only check for a
> namespace? According to the following tracker issue, if a package
> doesn't have a namespace, it won't drop to using data.frame's anyway.
> 
> https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1074&group_id=240&atid=978
> 
> How about something like this?
> 
> cedta = function() {
>     # Calling Environment Data Table Aware
> 
>     te = topenv(parent.frame(2))
>     !isNamespace(te) ||
>         getNamespaceName(te) == "data.table" ||
>         "data.table" %in% names(getNamespaceImports(te))
> }
> 
> If I do that, I can execute the following:
> 
> sys.source("t.R", new.env(parent=.GlobalEnv))
> 
> with t.R as follows:
> 
> --------------------------
> TESTDT = data.table(a=as.integer(c(1,3,4,4,4,4,7)),
>                     b=as.integer(c(5,5,6,6,9,9,2)),
>                     v=1:7)
> setkey(TESTDT,a,b)
> x <- TESTDT[SJ(4,6), v, mult="first"]
> 
> test.data.table()
> --------------------------
> 
> I'm not sure if this'd break other stuff, though. I haven't tested it
> anymore than just doing this.
> 
> - Tom
> _______________________________________________
> 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