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

Error message should remind correct usage of indexing with logical vector column #1844

Closed
dracodoc opened this issue Sep 10, 2016 · 0 comments
Milestone

Comments

@dracodoc
Copy link
Contributor

It's pretty common in R to use a logical vector for selecting, but this fails:

> x <- data.table(b = c(FALSE, TRUE), d = 1:2)
> x
       b d
1: FALSE 1
2:  TRUE 2
> x[b]
Error in eval(expr, envir, enclos) : object 'b' not found
> x[(b)]
      b d
1: TRUE 2

This is a frequent mistake, see here and here

The problem can be avoided with more user friendly error message. For example:

Error in eval(expr, envir, enclos) : object 'b' not found
When 'i' is a single variable name, it is not considered an expression of column names and is instead evaluated in calling scope. 
If 'b' is intended to be used as logical vector to index, wrap 'b' with () as expression.
@mattdowle mattdowle added this to the v1.10.6 milestone Aug 5, 2017
mattdowle added a commit that referenced this issue Aug 5, 2017
Closes #1844 -- supplement error message when potentially subsetting by a logical vector in i without wrapping in ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants