Last active
August 20, 2022 15:02
-
-
Save randrescastaneda/b26ba2b6fba6ec31f2167596d41bd3cf to your computer and use it in GitHub Desktop.
Find Variables available in one data.frame not available in another.
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
#' Find variable that are not available in one on another data.frame | |
#' | |
#' @param x data.frame 1 | |
#' @param y data.frame 2 | |
#' | |
#' @return | |
#' @export | |
#' | |
#' @examples | |
extra_vars <- function(x, y) { | |
# ____________________________________________________________________________ | |
# on.exit #### | |
on.exit({ | |
}) | |
# ____________________________________________________________________________ | |
# Defenses #### | |
stopifnot( exprs = { | |
is.data.frame(x) | |
is.data.frame(y) | |
} | |
) | |
# ____________________________________________________________________________ | |
# Early returns #### | |
if (FALSE) { | |
return() | |
} | |
# ____________________________________________________________________________ | |
# Computations #### | |
x_no_y <- names(x)[!names(x) %in% names(y)] | |
y_no_x <- names(y)[!names(y) %in% names(x)] | |
cli::cli_alert_info("Variables in x not available in y:") | |
cli::cli_ul(x_no_y) | |
# ____________________________________________________________________________ | |
# Return #### | |
l <- list(x_no_y = x_no_y, | |
y_no_x = y_no_x) | |
return(invisible(l)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment