Created
May 14, 2019 17:38
-
-
Save mkearney/bb2ce47eb635c14d5f99151636e26b21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Conditionally apply expressions on a data object | |
#' | |
#' @param .data Input data | |
#' @param condition A logical value to determine whether to use .if or .else | |
#' @param .if Formula or function to apply to intput data when condition is TRUE | |
#' @param .else Formula or function to apply to intput data when condition is FALSE | |
#' @return Output of appropriate .if/.else call | |
#' @export | |
#' @importFrom rlang as_closure | |
do_if_else <- function(.data, condition, .if, .else = identity) { | |
if (condition) { | |
call <- rlang::as_closure(.if) | |
} else { | |
call <- rlang::as_closure(.else) | |
} | |
do.call(call, list(.data)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment