confirmSameValue <- function(DT1, DT2, colsToCompare, by=intersect(key(DT1), key(DT2)), by1=by, by2=by, colsToCompare1=colsToCompare, colsToCompare2=colsToCompare
                        , suffixes=c(".acc", ".anal", "anals"), aggFunc="sumn", tol=1e3, na.check=TRUE, round_format=NULL
                        , title=NULL
                        , verbose=TRUE) {

  aggFunc <- match.fun(aggFunc)

  DT1.nm <- pasteC(capture.output(substitute(DT1)), C=" ")
  DT2.nm <- pasteC(capture.output(substitute(DT2)), C=" ")

  if (grepl("\\[", DT1.nm))
    DT1.nm <- strsplit(DT1.nm, "\\[")[[c(1,1)]]
  if (grepl("\\[", DT2.nm))
    DT2.nm <- strsplit(DT2.nm, "\\[")[[c(1,1)]]

  pat.suf <- paste0(escapeRegEx(suffixes), "$")

  if (any(wh.suf <- sapply(pat.suf, function(x) sum(grepl(x, c(DT1.nm, DT2.nm)))==1))) {
    suffixes <- suffixes[wh.suf]
  }


  ## --------- .SDcols1 --------------- ##
  .SDcols1 <- intersect(colsToCompare1, names(DT1))
  if (!length(.SDcols1))
    .SDcols1 <- intersect(paste0(colsToCompare1, suffixes), names(DT1))
  if (!length(.SDcols1))
    stop ("No valid columns in colsToCompare1")
  ## --------- .SDcols2 --------------- ##
  .SDcols2 <- intersect(colsToCompare2, names(DT2))
  if (!length(.SDcols2))
    .SDcols2 <- intersect(paste0(colsToCompare2, suffixes), names(DT2))
  if (!length(.SDcols2))
    stop ("No valid columns in colsToCompare2")
  ## ---------------------------------- ##


  if (length(.SDcols1) != length(.SDcols2))
    warning (".SDcols1 and .SDcols2 have different lengths")

  browser(expr=inDebugMode(c("confirmSameValue", "aggregate")), text="in confirmSameValue() before merging")

  ## Verbose output
  if (verbose && !is.null(title))
    cat("\nComparing for ", title, "\n\n")

  ## Merge the two
  DT.confirm <- merge(
        DT1[, lapply(.SD, aggFunc), keyby=by1, .SDcols=.SDcols1]
      , DT2[, lapply(.SD, aggFunc), keyby=by1, .SDcols=.SDcols2]
      , all=TRUE)

  diffCol <- paste0("diff_", colsToCompare1)
  percCol <- paste0("perc.diff_", colsToCompare1)

  ## Auto suffixes
  if (any(wh.same <- (.SDcols1 == .SDcols2))) {
    .SDcols1[wh.same] <- paste0(.SDcols1[wh.same], ".x")
    .SDcols2[wh.same] <- paste0(.SDcols2[wh.same], ".y")
  }

  DT.confirm[, (diffCol) := get(.SDcols1) - get(.SDcols2)]
  DT.confirm[, (percCol) := get(diffCol)  / get(.SDcols1)]

  if (na.check == TRUE) {
    NA_0 <- DT.confirm[, {L <- get(.SDcols1); R <- get(.SDcols2); (L == 0 & is.na(R)) | (is.na(L) & R == 0)}]
    msg.NA_0 <- ifelse(!any(NA_0), "", (sprintf("%3i of the %i rows (%6s) are of the form (0 == NA). This may be due to NAs introduced from merging\n", sum(NA_0), length(NA_0), fwp(sum(NA_0)/length(NA_0), dec=1))))
  } else 
    msg.NA_0 <- ""


  DT.confirm[, .equal := equals0(get(diffCol), tol=tol, na.check=na.check)]
  if (na.check)
    DT.confirm[NA_0, .equal := TRUE]

  if (all(DT.confirm$.equal)) {
    msg <- paste0(ifelse(msg.NA_0 != "", "Otherwise ", ""), "All are equal")
  } else {
    msg <- DT.confirm[, (sprintf("%3i of the %i rows (%6s) are NOT equal", sum(!.equal), .N, fwp(sum(!.equal)/.N, dec=1)))]
    if (verbose)
      print(formnumb(DT.confirm[!(.equal)], round=round_format))
  }

  verboseMsg(verbose, "\n", msg.NA_0, msg, func="message")
  return(invisible(DT.confirm))
}