Skip to content

Instantly share code, notes, and snippets.

@brodieG
Created December 27, 2020 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brodieG/89a1e8bf339fc1dc2e2ba1918bbd4847 to your computer and use it in GitHub Desktop.
Save brodieG/89a1e8bf339fc1dc2e2ba1918bbd4847 to your computer and use it in GitHub Desktop.
Using serialize With all.equal.environment
## 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