Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid partial matching of data.table column names #26

Open
achubaty opened this issue Jul 11, 2019 · 0 comments
Open

avoid partial matching of data.table column names #26

achubaty opened this issue Jul 11, 2019 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@achubaty
Copy link
Contributor

achubaty commented Jul 11, 2019

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"
@achubaty achubaty added the help wanted Extra attention is needed label Jul 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant