We already have a helpful error for accidentally treating a column as a table:
DT = data.table(vv = runif(100) > .5)
DT[vv]
# Error in `[.data.table`(DT, vv) :
# vv is not found in calling scope but it is a column of type logical. If you wish to select rows where that column contains TRUE, or perhaps that column contains row numbers of itself to select, try DT[(col)], DT[DT$col], or DT[col==TRUE] is particularly clear and is optimized. When the first argument inside DT[...] is a single symbol (e.g. DT[var]), data.table looks for var in calling scope.
However this doesn't appear if the culprit column happens to mask a function:
setnames(DT, 'vv', 'filter')
DT[filter]
# Error in `[.data.table`(DT, filter) :
# i has evaluated to type closure. Expecting logical, integer or double.
It would be nice if it's easy to extend the helpful message to such a case.
We already have a helpful error for accidentally treating a column as a table:
However this doesn't appear if the culprit column happens to mask a function:
It would be nice if it's easy to extend the helpful message to such a case.