-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adding option_fn
field to option_spec
#12
Conversation
"envir" = spec$envvar_fn(Sys.getenv(spec$envvar_name), spec$envvar_name), | ||
"option" = getOption(spec$option_name), | ||
"default" = get_option_default_value(x, optenv), | ||
if (missing(default)) stop(sprintf("option '%s' not found.", x)) | ||
else default | ||
) | ||
|
||
spec$option_fn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea that we can pass arbitrary arguments to option_fn
via ...
. However, if we allow for this, two other changes are required:
- The doc
#' @param ... Additional arguments unused
must be updated in line 8; - A more thorough check of
option_fn
is required, otherwise the user can get weird error messages or even worse, inconsistent failures/wrong results; - Depending on how strict we want to be with the signature of
option_fn
, we might introduce a little overhead here and check what arguments to pass tooption_fn
:
.call <- as.call(
c(
list(spec$option_fn$fn, value),
alist(x = x, default = default, env = env, ... = ..., source = source)[spec$option_fn$args]
)
)
eval(.call)
See my comment at option_spec
for the proposed utility function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! There are a few typos in the doc which shall be fixed. I also added two optional comments on the use of ...
in option_fn
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing spelling - thanks @tdeenes
Fixing spelling Co-authored-by: Dénes Tóth <tdeenes@users.noreply.github.com>
@dgkf I think you forgot to update the roxygen doc:
This should be modified to:
|
Adds
option_fn
, a function that may be applied to the return value of an option before its value is retrieved.Capabilities made possible:
opt()
to return the result of calling the function without having to consistently apply the function or wrap it in a specialized helper.opt()
Behaviors still under consideration:
@tdeenes, your feedback would be greatly appreciated if you can take a look