Skip to content
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

Add gradethis_default() lookup helper #245

Open
gadenbuie opened this issue Jun 3, 2021 · 1 comment
Open

Add gradethis_default() lookup helper #245

gadenbuie opened this issue Jun 3, 2021 · 1 comment
Assignees

Comments

@gadenbuie
Copy link
Member

Currently, we lookup gradethis options via getOption("gradethis.fail", "Fall back default"), which has a few disadvantages:

  • the correct fallback needs to be used in every case
  • it clutters the API since the preferred method for setting the defaults is via gradethis_setup()
  • it isn't easy to differentiate between actively supplied arguments and default values determined from global settings without resorting to sentinel values that further obscure the mechanics

We should add a helper for looking up global default values: gradethis_default()

fail <- function(
  message = gradethis_default("fail"),
  ...,
  hint = gradethis_default("fail.hint"),
  encourage = gradethis_default("fail.encourage")
) { ... }

where the documentation can better direct users to gradethis_setup() where those values are set since both functions would be documented in the same help page.

Internally, gradethis_default() could add an attr() that we could use to determine whether or not the argument value was supplied by the user or looked up from global options.

@gadenbuie
Copy link
Member Author

I implemented a version of this that — rather than taking the option as a character argument as in gradethis_default("<option>") — is instead a list of functions that access the current default value. The list is named gradethis_settings and its structure enables auto-complete:

image

I was thinking about a developer-facing interface at the time, hence gradethis_settings rather than gradethis_default to avoid clashes with our internal list of default values.

With a little extra work, we could allow the functions to also operate as setters when provided with a value.

# Set fail.hint default value
gradethis_settings$fail.hint(TRUE)

If we export this object, then the function signature for fail() (and others) would look like this:

fail <- function(
  message = gradethis_settings$fail(),
  ...,
  hint = gradethis_settings$fail.hint(),
  encourage = gradethis_settings$fail.encourage()
) { 
  # ... 
}

I'm not completely sold on the name, gradethis_config or gradethis_options also come to mind, but I went with gradethis_settings since it's closer to gradethis_setup().

@gadenbuie gadenbuie self-assigned this Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant