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

specific handling for 1:.N --> .I in seq_linter() #2283

Closed
wants to merge 1 commit into from
Closed

Conversation

MichaelChirico
Copy link
Collaborator

Closes #2101

@AshesITR
Copy link
Collaborator

Careful: .I is not seq_len(.N) in the presence of by:

library(data.table)
df <- data.table(grp = rep(c("a", "b"), each = 2L), val = rep(c(1L, 2L), times = 2L))
df[, rx := .I, by = .(grp)][rx > 1, val := 0L]
df
#>    grp val rx
#> 1:   a   1  1
#> 2:   a   0  2
#> 3:   b   0  3
#> 4:   b   0  4
df <- data.table(grp = rep(c("a", "b"), each = 2L), val = rep(c(1L, 2L), times = 2L))
df[, rx := seq_len(.N), by = .(grp)][rx > 1, val := 0L]
df
#>    grp val rx
#> 1:   a   1  1
#> 2:   a   0  2
#> 3:   b   1  1
#> 4:   b   0  2

Created on 2023-11-15 with reprex v2.0.2

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

Successfully merging this pull request may close these issues.

seq_linter() should recommend .I for 1:.N
2 participants