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

Enhance Error Message for using := or let in Non-data.table-aware Environment #6019

Merged
merged 7 commits into from
Mar 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@
# the drop=NULL is to sink drop argument when dispatching to [.data.frame; using '...' stops test 147
if (!cedta()) {
# Fix for #500 (to do)
if (any(grepl(":=|let", substitute(j)))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was some discussion about tidyverse and the rlang version of :=. Another version to consider would be this :

if (substitute(j) %iscall% c(":=", "let"))

I also researched tidyverse. The above implementation should be faster and more reliable than original proposal, but it does seem unlikely for us to encounter the way := is used in dplyr.

https://dplyr.tidyverse.org/articles/programming.html

# Throw a specific error message
stopf("[ was called on a data.table in an environment that is not data.table-aware (i.e. cedta()), but ':=' or 'let' was used, implying the owner of this call really intended for data.table methods to be called. See vignette('datatable-importing') for details on properly importing data.table.")

Check warning on line 150 in R/data.table.R

View check run for this annotation

Codecov / codecov/patch

R/data.table.R#L150

Added line #L150 was not covered by tests
}
Nargs = nargs() - (!missing(drop))
ans = if (Nargs<3L) { `[.data.frame`(x,i) } # drop ignored anyway by DF[i]
else if (missing(drop)) `[.data.frame`(x,i,j)
Expand Down
Loading