dgkf / options

Simple, Consistent Package Options
https://dgkf.github.io/options
Other
25 stars 1 forks source link

[bug?] `format.options_env()` tries to evaluate options even if unset #14

Closed tdeenes closed 5 months ago

tdeenes commented 6 months ago
optenv <- define_option("test")
print(optenv)
# Error: argument is missing, with no default

I think the problem is with line values <- as.list(x) in format.options_env(). The call as.list() forces the evaluation of promises, which fails if the promise is an empty symbol (bquote()) or references any non-existing symbol in the environment. Instead of as.list(), the function should loop through the individual elements and render the unevaluated expression (see ?delayedAssign for the eval(substitute(substitute(...))) idiom, or simply take the specs defaults) and its evaluated value only if available. Otherwise, render <unset> or the error message, but do not fail.

dgkf commented 6 months ago

Certainly a bug. At the very minimum, the error message is unhelpful, but I think overall the behavior can certainly be improved. Thanks for reporting this.