I found this strange behavior when assigning a value to a position. If the variable has the same name as a column it thinks we are talking about the column:
You can always use get, which allows you to specify the environment:
get
dt1[1, a := get("a", envir = .GlobalEnv)] # a #1: 18
Or just:
a <- 42 dt1[1, a := .GlobalEnv$a] # a #1: 42