Skip to content

Instantly share code, notes, and snippets.

@DavisVaughan
Created May 7, 2020 22:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavisVaughan/3ebeec82aedc474851d00cb914626541 to your computer and use it in GitHub Desktop.
Save DavisVaughan/3ebeec82aedc474851d00cb914626541 to your computer and use it in GitHub Desktop.
library(rlang)
#> Warning: package 'rlang' was built under R version 3.6.2
generator <- function() {
# ~ 80mb
x <- 1:1e7 + 0
# `x` is in this function env
function() {
1
}
}
bad_fn <- generator()
# oh shoot!
head(fn_env(bad_fn)$x)
#> [1] 1 2 3 4 5 6
# so big!
lobstr::obj_size(bad_fn)
#> 80,012,912 B
object.size(bad_fn)
#> 4216 bytes
@DavisVaughan
Copy link
Author

library(rlang)

test_recipe <- function(x) {
  rlang::enquo(x)
}

generator <- function() {
  # ~ 80mb
  x <- 1:1e7 + 0
  
  stuff <- 1
  
  # `x` is in this function env
  test_recipe(stuff)
}

bad_quo <- generator()
bad_quo
#> <quosure>
#> expr: ^stuff
#> env:  0x7fc5335251f8

bad_quo
#> <quosure>
#> expr: ^stuff
#> env:  0x7fc5335251f8

lobstr::obj_size(bad_quo)
#> 80,000,952 B

head(quo_get_env(bad_quo)$x)
#> [1] 1 2 3 4 5 6

Created on 2021-04-15 by the reprex package (v1.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment