R is case-sensitive, so var2 and Var2 are different objects.
You can mix quoted and unquoted variables, but you need to be aware how they are used:
library(data.table)
mt <- data.table(mtcars)
mt[, .N, by = c("cyl", "gear")] # use quotes when using a vector
mt[, .N, by = list(cyl, gear)] # don't use quotes when using a list
mt[, .N, .(cyl, gear)] # same but less typing
mt[, .N, keyby = .(cyl, gear)] # keyby keys (orders) the output