-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle unexported functions in *Defaults()
setDefaults() was not able to find unexported functions (e.g. getQuote.av()), so users could not set defaults for them. The bulk of the changes are in setDefaults() in order to verify the function exists, exported or not, and has a call to importDefaults(). Check if the name is a function in getDefaults() and unsetDefaults(). Use try() to capture instances where the function is not exported. We do not need to re-verify because the default options will only exist if setDefaults() created them. Fixes #316.
- Loading branch information
1 parent
af6fa37
commit a8b3fc3
Showing
3 changed files
with
214 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
library(quantmod) | ||
|
||
api.key <- "abc" | ||
src <- "xyz" | ||
|
||
# {{{ Unexported function | ||
|
||
### function name as character | ||
### -------------------------- | ||
|
||
## default argument as character | ||
# set | ||
setDefaults("getQuote.av", api.key = "abc") | ||
default.key <- getDefaults("getQuote.av")[["api.key"]] | ||
stopifnot(identical("'abc'", default.key)) | ||
# unset | ||
unset <- unsetDefaults("getQuote.av", confirm = FALSE) | ||
stopifnot(!is.null(unset)) # should not be NULL | ||
default.key <- getDefaults("getQuote.av")[["api.key"]] | ||
stopifnot(is.null(default.key)) | ||
|
||
## default argument as symbol | ||
# set | ||
setDefaults("getQuote.av", api.key = api.key) | ||
default.key <- getDefaults("getQuote.av")[["api.key"]] | ||
stopifnot(identical(sQuote(api.key), default.key)) | ||
# unset | ||
unset <- unsetDefaults("getQuote.av", confirm = FALSE) | ||
stopifnot(!is.null(unset)) # should not be NULL | ||
default.key <- getDefaults("getQuote.av")[["api.key"]] | ||
stopifnot(is.null(default.key)) | ||
|
||
### function name as symbol | ||
### ----------------------- | ||
|
||
## default argument as character | ||
# set | ||
setDefaults(getQuote.av, api.key = "abc") | ||
default.key <- getDefaults(getQuote.av)[["api.key"]] | ||
stopifnot(identical("'abc'", default.key)) | ||
# unset | ||
unset <- unsetDefaults(getQuote.av, confirm = FALSE) | ||
stopifnot(!is.null(unset)) # should not be NULL | ||
default.key <- getDefaults(getQuote.av)[["api.key"]] | ||
stopifnot(is.null(default.key)) | ||
|
||
## default argument as symbol | ||
fake.key <- "abc" | ||
# set | ||
setDefaults(getQuote.av, api.key = fake.key) | ||
default.key <- getDefaults(getQuote.av)[["api.key"]] | ||
stopifnot(identical(sQuote(fake.key), default.key)) | ||
# unset | ||
unset <- unsetDefaults(getQuote.av, confirm = FALSE) | ||
stopifnot(!is.null(unset)) # should not be NULL | ||
default.key <- getDefaults(getQuote.av)[["api.key"]] | ||
stopifnot(is.null(default.key)) | ||
|
||
# }}} Unexported function | ||
|
||
|
||
# {{{ Exported function | ||
|
||
### function name as character | ||
### -------------------------- | ||
|
||
## default argument as character | ||
# set | ||
setDefaults("getSymbols", src = "xyz") | ||
default.src <- getDefaults("getSymbols")[["src"]] | ||
stopifnot(identical("'xyz'", default.src)) | ||
# unset | ||
unset <- unsetDefaults("getSymbols", confirm = FALSE) | ||
stopifnot(!is.null(unset)) # should not be NULL | ||
default.src <- getDefaults("getSymbols")[["src"]] | ||
stopifnot(is.null(default.src)) | ||
|
||
## default argument as symbol | ||
# set | ||
setDefaults("getSymbols", src = src) | ||
default.src <- getDefaults("getSymbols")[["src"]] | ||
stopifnot(identical("'xyz'", default.src)) | ||
# unset | ||
unset <- unsetDefaults("getSymbols", confirm = FALSE) | ||
stopifnot(!is.null(unset)) # should not be NULL | ||
default.src <- getDefaults("getSymbols")[["src"]] | ||
stopifnot(is.null(default.src)) | ||
|
||
### function name as symbol | ||
### ----------------------- | ||
|
||
## default argument as character | ||
# set | ||
setDefaults(getSymbols, src = "xyz") | ||
default.src <- getDefaults(getSymbols)[["src"]] | ||
stopifnot(identical("'xyz'", default.src)) | ||
# unset | ||
unset <- unsetDefaults(getSymbols, confirm = FALSE) | ||
stopifnot(!is.null(unset)) # should not be NULL | ||
default.src <- getDefaults(getSymbols)[["src"]] | ||
stopifnot(is.null(default.src)) | ||
|
||
## default argument as symbol | ||
# set | ||
setDefaults(getSymbols, src = src) | ||
default.src <- getDefaults(getSymbols)[["src"]] | ||
stopifnot(identical("'xyz'", default.src)) | ||
# unset | ||
unset <- unsetDefaults(getSymbols, confirm = FALSE) | ||
stopifnot(!is.null(unset)) # should not be NULL | ||
default.src <- getDefaults(getSymbols)[["src"]] | ||
stopifnot(is.null(default.src)) | ||
|
||
# }}} Exported function |