Tuesday, October 4
Shadow

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                                                                  ####
  return(list(x_no_y = x_no_y, 
              y_no_x = y_no_x))

}

Leave a Reply