orderByPre <- function(prefixes, suffixes, dtable) {
#  arders afr.v1, afr.v2, afr.v3, bfr.v1, bfr.v2, bfr.v3
#   to    afr.v1, bfr.v1, afr.v2, bfr.v2, afr.v3, bfr.v3
#  with any remaining columns at front. 
  ordering <- unlist(lapply(suffixes, function(sfx) paste0(prefixes, sfx)))
  remaiing <- names(dtable)[!names(dtable) %in% ordering]
  c(remaiing, ordering)  
}  

## ALTERNATIVE TO orderByPre, if prefixes are in a nice list
  # colOrdering <- unlist(lapply(seq_along(mets[[1]]), function(item) sapply(2:length(mets), function(grp) mets[[c(grp, item)]])))
  # colOrdering <- c(names(v3)[!names(v3) %in% colOrdering], colOrdering)

#-------------------------------------------------#

v4 <- data.table(cid=1:3, key="cid")
newCols <- paste0("val", 1:8)
pfx <- c("afr.", "bfr.")

bfr <- paste0("bfr.", newCols)
afr <- paste0("afr.", newCols)

v4[, unlist(bfr) := lapply(1:length(newCols), function(x) abs(round(10*rnorm(nrow(v4)))))]
v4[, unlist(afr) := lapply(bfr, function(b) get(b, envir=parent.frame(2)) + 1 + abs(round(rnorm(nrow(v4)))))] 

setcolorder(v4, orderByPre(pfx, newCols, v4))

v4

mets.nms <- paste0("prec.inc.", newCols)
metsbfr  <- bfr
metsafr  <- afr


  # ASSIGNING
  v4[, eval(mets.nms) := mapply(function(b, a) {
    bfr <- get(b, envir=parent.frame(2))
    afr <- get(a, envir=parent.frame(2))
    (afr - bfr) / bfr }, 
    eval(metsbfr), 
    eval(metsafr)
    ), by=cid
  ]; v4 

  # Without assigning, just naming the column
  v4[, {x <- list(bfr.val3, afr.val1+afr.val2, afr.val2+afr.val3); names(x) <- c("hello", "wor", "ld"); x}, by=cid]
