Skip to content

Instantly share code, notes, and snippets.

@coolbutuseless
Last active August 16, 2019 12:05
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 coolbutuseless/01492f310863b0ff27948108ad15a829 to your computer and use it in GitHub Desktop.
Save coolbutuseless/01492f310863b0ff27948108ad15a829 to your computer and use it in GitHub Desktop.
I came here for an argument.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Simple demo of a 10 argument function
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nargs <- 10
f <- function() {}
fargs <- as.pairlist(setNames(rep(1, nargs), paste0('v', seq(nargs))))
formals(f) <- fargs
f
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Simple demo of a 1 million argument function
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nargs <- 1e6
f <- function() {'hello'}
fargs <- as.pairlist(setNames(rep(1, nargs), paste0('v', seq(nargs))))
formals(f) <- fargs
f()
# 160 MB function!
lobstr::obj_size(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment