I've read the data.table documentation several times but I still can't wrap my head around how to do some operations; more generally I still haven't understood the underlying "philosophy" on how to work with variable names. Consider this example problem:
I have a data table with variables 'a', 'b', 'c', 'd':
> dt <- data.table(a=c(1,1,2), b=1:3, c=11:13, d=21:23)
> dt
a b c d
1: 1 1 11 21
2: 1 2 12 22
3: 2 3 13 23
Suppose my script interactively asks the user to input a column name and corresponding value that should be used to select rows. These two variables are stored in rowselectname and rowselectvalue:
> rowselectname
[1] "a"
> rowselectvalue
[1] 1
The script also interactively asks the user to select some row names of interest; their names are stored in colselectnames:
> colselectnames
[1] "b" "d"
Now I want to create a new data table from dt, with the rows for which rowselectname has the value rowselectvalue, and with the columns given by colselectnames. The only way I finally managed to do this is as follows:
> newdt <- dt[get(rowselectname)==rowselectvalue, ..colselectnames]
> newdt
b d
1: 1 21
2: 2 22
What I don't understand is why I have to use get() for the first selection and .. for the second. Why not get() for both (it doesn't work)? Or why not .. for both (doesn't work either)? This seems inconsistent to me, but maybe there's another way of doing this with a more consistent syntax. I think the most obvious should simply be newdt <- dt[rowselectname==rowselectvalue, colselectnames], which is how the rest of R seems to work.
I'd really appreciate someone explaining to me how to look at this to make sense of the syntax.