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 merge_like_variables function #39

Open
mbcann01 opened this issue Oct 3, 2018 · 0 comments
Open

Add merge_like_variables function #39

mbcann01 opened this issue Oct 3, 2018 · 0 comments
Assignees
Labels
New Function Add new function/functionality

Comments

@mbcann01
Copy link
Member

mbcann01 commented Oct 3, 2018

I created this function for the DETECT 5-week pilot analysis. It's probably worth adding to bfuncs for future use. Just don't have time to do it now.

merge_like_variables <- function(.data, .x) {
  # Setup
  var <- enquo(.x) %>% quo_name()
  var_x <- paste(var, "x", sep = ".") %>% rlang::sym()
  var_y <- paste(var, "y", sep = ".") %>% rlang::sym()

  # Merge
  .data %>%
    mutate(
      out = case_when(
        is.na(!!var_x) ~ !!var_y %>% as.character(), # IF .x is missing use .y
        is.na(!!var_y) ~ !!var_x %>% as.character(), # IF .y is missing use .x
        !!var_x != !!var_y ~ "conflict",             # IF neither missing test for conflict
        TRUE ~ !!var_x %>% as.character()            # IF neither missing and no conflict just use .x
      )
    ) %>%
    pull(out)
}
@mbcann01 mbcann01 self-assigned this Oct 3, 2018
@mbcann01 mbcann01 added the New Function Add new function/functionality label Oct 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Function Add new function/functionality
Projects
None yet
Development

No branches or pull requests

1 participant