permeate_ <- function(DT, col, by, na.rm=TRUE) {
## For a given column, ensures the value is unique by group and 
##  permeates that value for the whole group

  browser(expr=inDebugMode(c("permeate_", "permeate")), text="at the very top of permeate_()")

  if (length(col) > 1 || !is.character(col))
    stop ("col must be a single length character")

  ## Check if col is in the DT. If not, issue warning and return DT unchanged
  if (col %ni% names(DT)) {
    warning ("Column '", col, "' is not in DT... Thus, nothing to permeate. Returning DT unchanged")
    return(invisible(DT))
  }

  ## Check if any of the by cols are NOT in DT. If not, FAIL
  if (any(by %ni% names(DT))) {
    stop (warningCols("The following 'by' columns are NOT in DT ", by[by %ni% names(DT)]))
  }

  ## -------------------------
  ## FAIL IF NOT UNIQUE
  ## Note to self:  We are checking for non-uniques before checking for NON-NA's since having 
  ##                non-unique values is usually indicative of a bug elsewhere in the code
  err.check  <- DT[, lunique(get(col), na.rm=na.rm) %in% 0:1, by=by]
  if (any(!(err.check$V1)))
    stop(sprintf("Column '%s' is not unique by=list(%s) [na.rm=%s].\nThere should be only a single value which will be permeated through the whole group.\n\nHINT, look at (and specifically):\n    %s[storeid %%in%% c(%s) & !is.na(%1$s)]\n    %s", col, pasteC(by, C=", "), na.rm, capture.output(substitute(DT)), commaSep(err.check[!(V1), head(storeid, 12)]), pasteC("# ", capture.output(head(err.check[!(V1)])), C="\n    ") ))
  ## -------------------------


  ## If there are no NAs, permeating is not needed. 
  if (!any(is.na(DT[[col]]))) {
    warning("No NAs in ", col, ". Nothing to permeate ")
    return(invisible(DT))
  }


  if (na.rm)
    invisible(DT[, (col) := unique(removeNA(get(col))), by=by])
  else
    invisible(DT[, (col) := unique(get(col)), by=by])
}
