R/union_tables.R

Defines functions union_tables

Documented in union_tables

#' union_tables
#' This function helps to bind identical descriptive objects together
#' @export union_tables

union_tables <-
  function(x1 = list(),
           x2 = list(),
           x3 = list(),
           x4 = list(),
           x5 = list(),
           x6 = list(),
           x7 = list(),
           x8 = list(),
           x9 = list()) {
    temp <- x1
    objects <- list(x2, x3, x4, x5, x6, x7, x8, x9)
    for (i in objects) {
      if (!is.null(unlist(i))) {
        if (ncol(i[[1]]) == ncol(temp[[1]])) {
          if (i[[4]] == temp[4]) {
            if (all.equal(temp[[2]], i[[2]])) {
              temp[[1]] <- rbind(temp[[1]], i[[1]])
            } else{
              warning(
                "The heading for two of the tables are not equal. The heading for the first object is considered"
              )
              temp[[1]] <- rbind(temp[[1]], i[[1]])
            }

          } else{
            stop("You're trying to union objects of different type")
          }
        } else{
          stop("The number of columns are not equals for the tables entered")
        }

      }
    }
    return(temp)
  }
nivesh22/descriptive documentation built on Jan. 22, 2020, 8:03 p.m.