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

Export masks for NSE-only constructs ., J, patterns and measure #6125

Merged
merged 34 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
16683b2
masking function
May 6, 2024
06841af
Merge branch 'master' into Masking-functions
Nj221102 May 6, 2024
0003f9a
Update data.table.R
Nj221102 May 9, 2024
f63ae30
Merge branch 'master' into Masking-functions
Nj221102 May 27, 2024
070978c
Merge branch 'master' into Masking-functions
Nj221102 Jun 1, 2024
86ea33c
Removed mask for pattern and measure
Jun 1, 2024
6700f0e
Merge branch 'master' into Masking-functions
Nj221102 Jun 2, 2024
e1772e6
exporting pattern and measure
Jun 3, 2024
3095edd
Merge branch 'master' into Masking-functions
Nj221102 Jun 3, 2024
a1fdd4e
added news entry
Jun 3, 2024
bda02d8
editing news item
Jun 3, 2024
82ca538
updating news
Jun 4, 2024
a971529
updating news item
Jun 7, 2024
fc2459d
updated news item
Jun 8, 2024
4715f4e
Merge branch 'master' into Masking-functions
Nj221102 Jun 8, 2024
8dc023a
Update NEWS.md
Nj221102 Jun 8, 2024
adfac00
Update NEWS.md
Nj221102 Jun 8, 2024
628f4df
Merge branch 'master' into Masking-functions
Nj221102 Jun 13, 2024
5df7403
updating news
Jun 13, 2024
6751a2b
delete comment
Jun 13, 2024
7f1cfed
Merge branch 'master' into Masking-functions
Nj221102 Jun 19, 2024
4058118
updated test and mask for J
Jun 19, 2024
22f9706
improved the error message
Jun 19, 2024
40101d4
updated error messages
Jun 19, 2024
1dc2c2c
improving error message
Jun 19, 2024
3510565
Merge branch 'master' into Masking-functions
Nj221102 Jun 20, 2024
5ebd8b6
Update NEWS.md
Nj221102 Jun 20, 2024
82ca346
Merge branch 'master' into Masking-functions
Nj221102 Jun 20, 2024
1d61cce
small changes
Jun 20, 2024
127b45e
Update vignettes/datatable-importing.Rmd
Nj221102 Jun 20, 2024
90cd873
Update NEWS.md
Nj221102 Jun 20, 2024
87e50e1
grammar
MichaelChirico Jun 20, 2024
80c56eb
updating error message
Jun 20, 2024
ea84607
updating example
Jun 20, 2024
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
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export(tstrsplit)
export(frank)
export(frankv)
export(address)
export(.SD,.N,.I,.GRP,.NGRP,.BY,.EACHI)
export(.SD,.N,.I,.GRP,.NGRP,.BY,.EACHI, ., J, measure, patterns)
Copy link
Member

Choose a reason for hiding this comment

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

warning: I imagine this (.) will break some revdeps. Let's see.

export(rleid)
export(rleidv)
export(rowid)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@

15. `dcast()` now issues a warning when `fun.aggregate` is used but not provided by the user. `fun.aggregate` defaults to `length` in this case. Previously, only a message was issued. However, relying on this default often signals unexpected duplicates in the data. Therefore, a stricter class of signal was deemed more appropriate, [#5386](https://github.com/Rdatatable/data.table/issues/5386). The warning is classed as `dt_missing_fun_aggregate_warning`, allowing for more targeted handling in user code. Thanks @MichaelChirico for the suggestion and @Nj221102 for the fix.

16. `.`, `J`, `measure`, and `patterns` are now exported for use within `[` and `melt()` functions, for consistency with`.N`, `.I`, `.GRP`, `.GRPI`, `.SD`, and `:=` which were the only previous NSE exports. This change means that package developers will no longer see CRAN NOTEs about these being undefined variables, and no longer need to provide dummy/NULL definitions of these in order to avoid such NOTEs. See [#5604](https://github.com/Rdatatable/data.table/issues/5604) and [#5277](https://github.com/Rdatatable/data.table/issues/5277). Thanks to @tdhock for the suggestions and @Nj221102 for implementing this improvement.

## TRANSLATIONS

1. Fix a typo in a Mandarin translation of an error message that was hiding the actual error message, [#6172](https://github.com/Rdatatable/data.table/issues/6172). Thanks @trafficfan for the report and @MichaelChirico for the fix.
Expand Down
9 changes: 8 additions & 1 deletion R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ methods::setPackageName("data.table",.global)
# (2) export() in NAMESPACE
# (3) add to vignettes/datatable-importing.Rmd#globals section
.SD = .N = .I = .GRP = .NGRP = .BY = .EACHI = NULL
J = function(...) {
stopf("The function 'J' should not be called here. 'J' is intended for use within the 'i' argument of data.table operations")
MichaelChirico marked this conversation as resolved.
Show resolved Hide resolved
}

. = function(...) {
stopf("The function '.' should not be called here. '.' can be used as an alias for 'list' within the square brackets of a data.table, DT[.]")
MichaelChirico marked this conversation as resolved.
Show resolved Hide resolved
}

# These are exported to prevent NOTEs from R CMD check, and checkUsage via compiler.
# But also exporting them makes it clear (to users and other packages) that data.table uses these as symbols.
# And NULL makes it clear (to the R's mask check on loading) that they're variables not functions.
MichaelChirico marked this conversation as resolved.
Show resolved Hide resolved
# utils::globalVariables(c(".SD",".N")) was tried as well, but exporting seems better.
# So even though .BY doesn't appear in this file, it should still be NULL here and exported because it's
# defined in SDenv and can be used by users.
Expand Down
2 changes: 1 addition & 1 deletion inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,7 @@ if (ncol(DT)==2L) setnames(DT,c("A","B")) # else don't stop under torture with s
test(714, DT[,z:=6:10], data.table(A=1:5,B=5,z=6:10))

# Test J alias is now removed outside DT[...] from v1.8.7 (to resolve rJava::J conflict)
test(715, J(a=1:3,b=4), error=base_messages$missing_function("J"))
test(715, J(a=1:3,b=4), error="The function 'J' should not be called here.")
MichaelChirico marked this conversation as resolved.
Show resolved Hide resolved

# Test get in j
DT = data.table(a=1:3,b=4:6)
Expand Down
2 changes: 1 addition & 1 deletion vignettes/datatable-importing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ aggr = function (x) {
}
```

The case for `data.table`'s special symbols (`.SD`, `.BY`, `.N`, `.I`, `.GRP`, `.NGRP`, and `.EACHI`; see `?.N`) and assignment operator (`:=`) is slightly different. You should import whichever of these values you use from `data.table`'s namespace to protect against any issues arising from the unlikely scenario that we change the exported value of these in the future, e.g. if you want to use `.N`, `.I`, and `:=`, a minimal `NAMESPACE` would have:
The case for `data.table`'s special symbols (`.SD`, `.BY`, `.N`, `.I`, `.GRP`, `.NGRP`, `.`, `J`, `patterns`, `measure` and `.EACHI`; see `?.N`) and assignment operator (`:=`) is slightly different. You should import whichever of these values you use from `data.table`'s namespace to protect against any issues arising from the unlikely scenario that we change the exported value of these in the future, e.g. if you want to use `.N`, `.I`, and `:=`, a minimal `NAMESPACE` would have:
Nj221102 marked this conversation as resolved.
Show resolved Hide resolved

```r
importFrom(data.table, .N, .I, ':=')
Expand Down
Loading