You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling opts(xs = NULL) , the function returns an options_list, which means the default values (passed as default= during declaration) are returned.
E.g.:
When calling opts(sx = "test"), the current (evaluated) value(s) of the xs option(s) are returned. This behavior leads to confusion when one updates the value of an option:
opt_set("test", "new_value")
## opts.NULL() returns the value at declaration
stopifnot(identical(opts()$test, "original_value"))
## opts.character returns the current value
stopifnot(identical(opts("test")$test, "new_value"))
I would argue opts(xs = NULL) should also return the current evaluated values, but for backward compatibility, we can leave it as it is and define a new method for logical xs.
#' @param xs a boolean flag (`TRUE` = all, `FALSE` = none) or a named logical vector indicating which options shall be evaluated instead of returning its default value#' @exportopts.logical<-function(xs, env= parent.frame()) {
env<- get_options_env(as_env(env), inherits=TRUE)
out<- as_options_list(env)
if (length(xs) ==0L) return(out)
is_named<- list_is_all_named(xs)
stopifnot(
"'xs' must be named if not a single boolean value"=is_named||
length(xs) ==1L
)
if (any(xs)) {
out[xs] <- lapply(names(out)[xs], opt, env=env)
}
out
}
I also noticed that opts is a generic without ... in its signature (hence, the methods miss ellipses, too). Is this intentional?
The text was updated successfully, but these errors were encountered:
Thanks for reporting this! Yes, this is very unintuitive. I agree, the NULL value should be equivalent to passing all the names of the defined options. I consider this a bug.
but for backward compatibility
Since the package hasn't yet hit v1.0.0, I'm partial to allowing breaking changes if it helps simplify the interface.
I also noticed that opts is a generic without ... in its signature (hence, the methods miss ellipses, too). Is this intentional?
Not intentional, and is a good practice I should adopt here. I didn't really imagine that other methods would need to be defined, but I don't feel the need to close any doors on anyone that finds some clever use for other methods.
When calling
opts(xs = NULL)
, the function returns anoptions_list
, which means the default values (passed asdefault=
during declaration) are returned.E.g.:
When calling
opts(sx = "test")
, the current (evaluated) value(s) of thexs
option(s) are returned. This behavior leads to confusion when one updates the value of an option:I would argue
opts(xs = NULL)
should also return the current evaluated values, but for backward compatibility, we can leave it as it is and define a new method for logicalxs
.I also noticed that
opts
is a generic without...
in its signature (hence, the methods miss ellipses, too). Is this intentional?The text was updated successfully, but these errors were encountered: