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

Warning for set / := when numToDo > nrow(x)? #3557

Open
MichaelChirico opened this issue May 12, 2019 · 5 comments
Open

Warning for set / := when numToDo > nrow(x)? #3557

MichaelChirico opened this issue May 12, 2019 · 5 comments

Comments

@MichaelChirico
Copy link
Member

Follow-up to #2837 inspired by #1885 / #3460

We decided running duplicated every time we run set/:= to help protect against duplicated assignment is overkill & an efficiency killer.

However, when length(i) > nrow(x), there's no need to run duplicated -- there's guaranteed to be at least one duplicate in i (Pigeonhole):

DT = data.table(a = 1L)
DT[c(1, 1), a := 2:3]

We could warn in this case?

@jangorecki
Copy link
Member

unless DT[c(1, NA), a := 2:3]

@franknarf1
Copy link
Contributor

Re @jangorecki 's example, you can use numToDo instead of length(i) then? That count is already recorded with NAs removed as seen in

> DT[c(1, NA), a := 2:3, verbose=TRUE]
Detected that j uses these columns: a 
Assigning to 1 row subset of 1 rows
RHS_list_of_columns == false

I guess this would just be adding a warning near the message above

if (verbose) Rprintf("Assigning to %d row subset of %d rows\n", numToDo, nrow);

Related #2022

@MichaelChirico MichaelChirico changed the title Warning for set / := when length(i) > nrow(x)? Warning for set / := when numToDo > nrow(x)? May 13, 2019
@MichaelChirico
Copy link
Member Author

Thanks Frank/Jan, yes length(i) is not the condition we should use but it seems numToDo would be the corrected adjustment.

Main Q is whether we thing this is warning-worthy behavior? Or perhaps just something to append to/reiterate in the verbose message?

@jangorecki
Copy link
Member

@MichaelChirico lets start with verbose message, this at least won't make any breaking changes

@jangorecki
Copy link
Member

isn't it duplicate of #2022 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants