I want to allow users of my function to use arbitrary column names, and I need to refer to these in a data.table. Getting a column name from a var works except when the name of the var is also a column of the dt. I would like a solution to modify my reference approach (i.e. get(id) ) so that it works in the case where the variable and column name overlap, as well as the case where they don't -- with data.table v1.14.0 when a column has the same name as the variable (which contains the desired column reference), the column takes precedence which breaks the get(id).
dt=data.table(id='id1')
id='id'
dt[get(id) %in% 'id1',] #fails
dt=data.table(subject='id1')
id='subject'
dt[get(id) %in% 'id1',] #works
There are quite some questions related to referencing column names via variables, but I couldn't find a solution that avoids this kind of corner case where the user happens to use the same column names as my reference variables.