-
-
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(). Then we always capture the call in getDefaults() and unsetDefaults() to avoid the possibility that 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 4468a59
Showing
3 changed files
with
156 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,57 @@ | ||
library(quantmod) | ||
|
||
|
||
### tests with character function name | ||
# set | ||
setDefaults("getQuote.av", api.key = "abc") | ||
default.key <- getDefaults("getQuote.av")[["api.key"]] | ||
stopifnot(identical("'abc'", default.key)) | ||
# unset | ||
unsetDefaults("getQuote.av", confirm = FALSE) | ||
default.key <- getDefaults("getQuote.av")[["api.key"]] | ||
stopifnot(is.null(default.key)) | ||
|
||
|
||
### tests with character function name and symbol default | ||
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 | ||
unsetDefaults("getQuote.av", confirm = FALSE) | ||
default.key <- getDefaults("getQuote.av")[["api.key"]] | ||
stopifnot(is.null(default.key)) | ||
|
||
|
||
### tests with exported symbol function name | ||
# set | ||
setDefaults(getSymbols, src = "abc") | ||
default.key <- getDefaults(getSymbols)[["src"]] | ||
stopifnot(identical("'abc'", default.key)) | ||
# unset | ||
unsetDefaults(getSymbols, confirm = FALSE) | ||
default.key <- getDefaults("getSymbols")[["api.key"]] | ||
stopifnot(is.null(default.key)) | ||
|
||
|
||
# set | ||
setDefaults(getQuote.av, api.key = "abc") | ||
default.key <- getDefaults(getQuote.av)[["api.key"]] | ||
stopifnot(identical("'abc'", default.key)) | ||
# unset | ||
unsetDefaults(getQuote.av, confirm = FALSE) | ||
default.key <- getDefaults("getQuote.av")[["api.key"]] | ||
stopifnot(is.null(default.key)) | ||
|
||
|
||
# tests with symbol function name and symbol default | ||
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 | ||
unsetDefaults(getQuote.av, confirm = FALSE) | ||
default.key <- getDefaults("getQuote.av")[["api.key"]] | ||
stopifnot(is.null(default.key)) |