expecting column names

Take a look at what happens when one of the outputed columns is used for merging 

## CREATE SAMPLE DATA
#-------------------------------#
  columnNames <- paste0("COL0", 1:5)  
  silent <- lapply(columnNames, assign, 1:10, envir=.GlobalEnv)
  test <- data.table(cid=LETTERS[1:10], sapply(columnNames, function(x) get(x, envir=parent.frame(2))), key="cid")
  # CLEAR LOCALLY
  silent <- lapply(columnNames, assign, "Wrong One", envir=.GlobalEnv)
  rm(columnNames)
#-------------------------------#



  # find column names with a pattern.  
  #  Also include the key column, cid
    columnsUsing <- c(names(test)[grep("COL", names(test))])
    newColNames  <- paste0("NewCol", 1:length(columnsUsing))

  # NAMING THE COLUMNS, WITHOUT ASSIGNING.
    # Use `mapply` almost works, but the result is not a data.table
    test[, mapply(function(nam, x)  nam = get(x, envir=parent.frame(2)), newColNames, columnsUsing)]
  
    # Using `lapply` DOES NOT WORK
    test[, c(newColNames) = lapply(columnsUsing, function(x) get(x, envir=parent.frame(2)))]

$----------------------------------------------------------------------------$
    # HOWEVER! You can first name the list that is used in lapply
    test[, {names(columnsUsing) <- newColNames; 
            lapply(columnsUsing, function(x) get(x, envir=parent.frame(2)))}]
$----------------------------------------------------------------------------$


$----------------------------------------------------------------------------$
  # assigning 
    test[, c(newColNames) := lapply(columnsUsing, function(x)  get(x, envir=parent.frame(2)))]
$----------------------------------------------------------------------------$


    getCols <- function(colNames)  {
#      lapply(colNames, function(x)  get(x, envir=parent.frame(2)))    
       for (i in 1:6)
         print(ls(pattern="New*", all.names=TRUE, envir=parent.frame(i) ))
       return("OK")
    }

  test[, getCols(columnsUsing)]
  test[, ls(pattern="New*", all.names=TRUE, envir=parent.frame(i) )]
