-
-
Save favstats/2a7ea96bb6f9e60de8afe52889d1ea05 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
library(dplyr) | |
do_if <- function(.data, condition, call){ | |
if(condition){ | |
.x <- .data | |
call_str <- call %>% | |
as.character %>% | |
.[2] | |
out <- eval(rlang::parse_expr(call_str)) | |
return(out) | |
} else { | |
return(.data) | |
} | |
} | |
any_condition <- T | |
mtcars %>% | |
do_if(any_condition, ~{ | |
.x %>% | |
filter(cyl == 6) %>% | |
mutate(x = disp > 170) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment