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

Export is_selector_registered() function #163

Closed
ddsjoberg opened this issue Jun 23, 2022 · 2 comments · Fixed by #164
Closed

Export is_selector_registered() function #163

ddsjoberg opened this issue Jun 23, 2022 · 2 comments · Fixed by #164

Comments

@ddsjoberg
Copy link
Collaborator

ddsjoberg commented Jun 23, 2022

Export a utility that is the top section of .generic_selector(): a predicate indicating whether or not the table/var_info data has been registered.

.generic_selector <- function(variable_column, select_column, select_expr, fun_name) {
  # ensuring the proper data has been scoped to use this function
  if (!exists("df_var_info", envir = env_variable_type) ||
      (exists("df_var_info", envir = env_variable_type) &&
       !all(c(variable_column, select_column) %in% names(env_variable_type$df_var_info)))) {
    cli_alert_danger("Cannot use selector '{fun_name}()' in this context.")
    stop("Invalid syntax", call. = FALSE)
  }

  # selecting the variable from the variable information data frame
  env_variable_type$df_var_info %>%
    dplyr::select(all_of(c(variable_column, select_column))) %>%
    dplyr::filter(stats::complete.cases(.)) %>%
    dplyr::filter({{ select_expr }}) %>%
    dplyr::pull(all_of(variable_column)) %>%
    unique()
}

is_selector_registered <- function(variable_column, select_column) {
  !exists("df_var_info", envir = env_variable_type) ||
      (exists("df_var_info", envir = env_variable_type) &&
       !all(c(variable_column, select_column) %in% names(env_variable_type$df_var_info)))
}
@ddsjoberg ddsjoberg changed the title Export is_selector_registererd() function Export is_selector_registered() function Jun 23, 2022
@larmarange
Copy link
Owner

Ok. Note: the name should start with a dot as the other helpers

@larmarange
Copy link
Owner

Please have a look at #164

Note that I have inverted the condition: to be registered, you need both column in env_variable_type$df_var_info

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