I have read up on the differences between expect_equal and expect_identical.
That being said, I have a function which produces a data table that looks like:
Thing1 Thing2 Thing3
Thing1 34.6 23.4 54.2
Thing2 34.7 33.2 32.1
Thing3 32.7 33.5 33.8
structure(list(` ` = c("Thing1", "Thing2", "Thing3"), `Thing1` = c(34.6,
34.7, 32.7), `Thing2` = c(32.4, 33.2, 33.5), `Thing3` = c(33,
32.1, 33.8)), .Names = c(" ", "Thing1", "Thing2", "Thing3"), row.names = c(NA,
-3L), class = c("data.table", "data.frame"))
Let's call this table output
. I save this data.table in a .rds, then reload it with readRDS. This new table is called test
. The structure is unchanged, and only the pointers differ. Despite this, running identical(test, output)
yields false. Again, the structures are identical expect for the pointer. All classes are the same.
However, this: identical(as.data.table(test), output)
yields TRUE
. Does anyone have any idea what's going on here? It's not a simple class issue. I'm at a loss.
You can recreate this issue yourself by doing something like:
x <- as.data.table(mtcars)
saveRDS(x, "~/test.rds")
y <- readRDS("~/test.rds")
str(x)
str(y)
identical(x, y)
UPDATE
I checked mem_change()
on both objects, and it is different. However, object.size()
is the same.