Created
September 18, 2013 04:18
-
-
Save Sleepingwell/6604496 to your computer and use it in GitHub Desktop.
A little mechanism for setting options for an R package.
This file contains 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
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