Created
December 27, 2020 01:32
-
-
Save brodieG/89a1e8bf339fc1dc2e2ba1918bbd4847 to your computer and use it in GitHub Desktop.
Using serialize With all.equal.environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Serialization Does Not Trigger Promises | |
fx <- ff(stop('boom')) | |
fxa <- ff(stop('boom')) | |
fy <- ff(stop('boom boom')) | |
identical(serialize(fx, NULL), serialize(fxa, NULL)) | |
## [1] TRUE | |
identical(serialize(fx, NULL), serialize(fy, NULL)) | |
## [1] FALSE | |
## Detects Ancestry or Content Differences | |
enva <- list2env(list(y=5)) | |
envb <- list2env(list(y=6)) # content | |
envc <- list2env(list(y=5), parent=new.env()) # ancestry | |
ff1 <- local(function(i) function(x) x + i, envir=enva) | |
ff2 <- local(function(i) function(x) x + i, envir=envb) | |
ff3 <- local(function(i) function(x) x + i, envir=envb) | |
f1 <- ff1(1) | |
f2 <- ff2(1) | |
f3 <- ff3(1) | |
identical(serialize(f1, NULL), serialize(f2, NULL)) | |
## [1] FALSE | |
identical(serialize(f1, NULL), serialize(f3, NULL)) | |
## [1] FALSE | |
## Works with `...` too: | |
ff <- function(...) function(x) x + sum(...) | |
f1 <- ff(1, 2, 3) | |
f2 <- ff(1, 2, 3) | |
identical(serialize(f1, NULL), serialize(f2, NULL)) | |
## [1] TRUE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment