Skip to content

Instantly share code, notes, and snippets.

@Sleepingwell
Created September 18, 2013 04:18
Show Gist options
  • Save Sleepingwell/6604496 to your computer and use it in GitHub Desktop.
Save Sleepingwell/6604496 to your computer and use it in GitHub Desktop.
A little mechanism for setting options for an R package.
opt.env <- new.env()
setOption <- function(auth_token, remaining_limit) {
cl <- as.list(match.call()[-1])
invisible(mapply(assign, names(cl), cl, MoreArgs=list(envir=opt.env)))
}
getOption <- function(opt) if(exists(opt, envir=opt.env)) get(opt, envir=opt.env) else NA
#---- test ---
setOption(auth_token='val', remaining_limit=2)
getOption('auth_token')
getOption('remaining_limit')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment