brodieG / unitizer

Easy R Unit Tests
Other
39 stars 6 forks source link

Conflicts with `abstract` and `ggplot2` #204

Closed brodieG closed 7 years ago

brodieG commented 7 years ago

Weird stuff happening on second evaluation in a fresh session while testing alike:

> unitize_dir()

Error in (function (cl, name, valueClass)  : 
  c("assignment of an object of class “FacetNull” is not valid for @‘source’ in an object of class “functionWithTrace”; is(value, \"environment\") is not TRUE", "assignment of an object of class “Facet” is not valid for @‘source’ in an object of class “functionWithTrace”; is(value, \"environment\") is not TRUE", "assignment of an object of class “ggproto” is not valid for @‘source’ in an object of class “functionWithTrace”; is(value, \"environment\") is not TRUE"
)
Error in (function (cl, name, valueClass)  : 
  c("assignment of an object of class “FacetNull” is not valid for @‘source’ in an object of class “functionWithTrace”; is(value, \"environment\") is not TRUE", "assignment of an object of class “Facet” is not valid for @‘source’ in an object of class “functionWithTrace”; is(value, \"environment\") is not TRUE", "assignment of an object of class “ggproto” is not valid for @‘source’ in an object of class “functionWithTrace”; is(value, \"environment\") is not TRUE"
)
In addition: Warning message:
In FUN(X[[i]], ...) :
  Failed attempting to trace `library`; see prior errors
Error in (function (cl, name, valueClass)  : 
  c("assignment of an object of class “FacetNull” is not valid for @‘source’ in an object of class “functionWithTrace”; is(value, \"environment\") is not TRUE", "assignment of an object of class “Facet” is not valid for @‘source’ in an object of class “functionWithTrace”; is(value, \"environment\") is not TRUE", "assignment of an object of class “ggproto” is not valid for @‘source’ in an object of class “functionWithTrace”; is(value, \"environment\") is not TRUE"
)
In addition: Warning message:
In FUN(X[[i]], ...) : Failed attempting to trace `attach`; see prior errors

For reference, this seems to be related to:

> library(ggplot2)
> df1 <- data.frame(x = runif(20), y = runif(20))
> df2 <- data.frame(x = runif(20), y = runif(20), z = rep(c("a", 
+     "b"), 10))
> df3 <- data.frame(a = runif(30), b = runif(30))
> g1 <- ggplot(df1) + geom_point(aes(x = x, y = y))
> g2 <- ggplot(df1) + geom_line(aes(x = x, y = y))
> g3 <- ggplot(df3) + geom_point(aes(x = a, y = b))
> g4 <- ggplot(df1, aes(x = x, y = y)) + geom_point() + geom_line()
> g.abs <- abstract(g1)
> alike(g.abs, g1)
[1] "`g1$layers[[1]]` should be class \"FacetNull\" (is \"environment\")"

| Value mismatch: 

< .ref                                   > .new                                 
@@ 1 @@                                  @@ 1 @@                                
< [1] TRUE                               > [1] "`g1$layers[[1]]` should be class
~                                        :  \"FacetNull\" (is \"environment\")" 

Notice the FacetNull.

This seems to happen before test evaluation. To reproduce:

unitize()  # select alike
# quit immediately
unitize()   # then get the warnings

So it seems that after loading ggplot we can no longer trace stuff.

brodieG commented 7 years ago

This was actually a problem with abstract replacing environments with the empty env as a default action, but then re-attaching classes to that environment.