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

FR: get option names #15

Closed
tdeenes opened this issue Apr 25, 2024 · 1 comment · Fixed by #17
Closed

FR: get option names #15

tdeenes opened this issue Apr 25, 2024 · 1 comment · Fixed by #17

Comments

@tdeenes
Copy link
Contributor

tdeenes commented Apr 25, 2024

It would be useful to have an official interface for retrieving names of available options from an environment without evaluating any of those options. Currently we can achieve this by options::opts(NULL, env = myenv) |> names() but after the expected refactoring of #13 it will not be available.

I am thinking of something like this:

#' Get the names of declared options
#'
#' @inheritParams get_options_env
#' @export
opt_names <- function(env = parent.frame(), ..., inherits = TRUE) {
  as_env(env) |>
    get_options_env(..., inherits = inherits) |>
    ls(envir = _, all.names = TRUE, sorted = FALSE)
}
@dgkf
Copy link
Owner

dgkf commented May 11, 2024

I'm still debating what the right path will be for this... In an ideal world, you'd be able to do names(opts()), without eagerly evaluating opts() and still returning the values as they existed when you called opts().

I don't think there's going to be a good way to do that without a lot of changes, so in absence of deciding on an ideal path forward, for now I'm going to expose get_options_env() so that you can do names(get_options_env()).

I can't guarantee this will be around forever, but I'll be sure you have a substitute for accessing names, whatever that might look like.

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

Successfully merging a pull request may close this issue.

2 participants