LandR
LandR copied to clipboard
avoid partial matching of data.table column names
using $ to extract columns is dangerous due to partial matching. the wrong columns may inadvertently be extracted.
> library(data.table)
> DT <- data.table(col1 = letters, col20 = LETTERS)
> DT$col2
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S"
[20] "T" "U" "V" "W" "X" "Y" "Z"
Ensure that columns are extracted using data.table syntax ([["colName"]]):
> DT[["col2"]]
NULL
> DT[["col20"]]
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S"
[20] "T" "U" "V" "W" "X" "Y" "Z"