Skip to content

Instantly share code, notes, and snippets.

@randrescastaneda
Last active August 20, 2022 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randrescastaneda/b26ba2b6fba6ec31f2167596d41bd3cf to your computer and use it in GitHub Desktop.
Save randrescastaneda/b26ba2b6fba6ec31f2167596d41bd3cf to your computer and use it in GitHub Desktop.
Find Variables available in one data.frame not available in another.
#' 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