Skip to content

Commit fab93a9

Browse files
Nj221102nitish jhaMichaelChirico
authored
Export masks for NSE-only constructs ., J, patterns and measure (#6125)
* masking function * Update data.table.R * Removed mask for pattern and measure * exporting pattern and measure * added news entry * editing news item * updating news * updating news item * updated news item * Update NEWS.md * Update NEWS.md * updating news * delete comment * updated test and mask for J * improved the error message * updated error messages * improving error message * Update NEWS.md Co-authored-by: Michael Chirico <michaelchirico4@gmail.com> * small changes * Update vignettes/datatable-importing.Rmd Co-authored-by: Michael Chirico <michaelchirico4@gmail.com> * Update NEWS.md Co-authored-by: Michael Chirico <michaelchirico4@gmail.com> * grammar * updating error message * updating example --------- Co-authored-by: nitish jha <nitishjha@nitishs-MacBook-Air.local> Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
1 parent 9be6872 commit fab93a9

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

NAMESPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export(tstrsplit)
2727
export(frank)
2828
export(frankv)
2929
export(address)
30-
export(.SD,.N,.I,.GRP,.NGRP,.BY,.EACHI)
30+
export(.SD,.N,.I,.GRP,.NGRP,.BY,.EACHI, ., J, measure, patterns)
3131
export(rleid)
3232
export(rleidv)
3333
export(rowid)

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100

101101
16. `print.data.table` gains new argument `show.indices` and option `datatable.show.indices` that allows the user to print a `data.table`'s indices as columns without having to modify the `data.table` itself. Thanks @MichaelChirico for the report and @joshhwuu for the PR.
102102
103+
17. `.`, `J`, `measure`, and `patterns` are now exported for use within `[` and `melt()`, for consistency with other NSE exports like `.N` and `:=`, [#5604](https://github.com/Rdatatable/data.table/issues/5604). Package developers can now import these names to avoid `R CMD check` `NOTE`s about them being undefined variables. Thanks to @MichaelChirico and @ylelkes for the suggestions and @Nj221102 for implementing.
104+
103105
## TRANSLATIONS
104106
105107
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.

R/data.table.R

+8
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,14 @@ address = function(x) .Call(Caddress, eval(substitute(x), parent.frame()))
27702770
stopf('Check that is.data.table(DT) == TRUE. Otherwise, :=, `:=`(...) and let(...) are defined for use in j, once only and in particular ways. See help(":=").')
27712771
}
27722772

2773+
J = function(...) {
2774+
stopf("J() called outside of [.data.table. J() is only intended for use in i.")
2775+
}
2776+
2777+
. = function(...) {
2778+
stopf(".() called outside of [.data.table. .() is only intended as an alias for list() inside DT[...].")
2779+
}
2780+
27732781
let = function(...) `:=`(...)
27742782

27752783
setDF = function(x, rownames=NULL) {

inst/tests/tests.Rraw

+1-1
Original file line numberDiff line numberDiff line change
@@ -2186,7 +2186,7 @@ if (ncol(DT)==2L) setnames(DT,c("A","B")) # else don't stop under torture with s
21862186
test(714, DT[,z:=6:10], data.table(A=1:5,B=5,z=6:10))
21872187

21882188
# Test J alias is now removed outside DT[...] from v1.8.7 (to resolve rJava::J conflict)
2189-
test(715, J(a=1:3,b=4), error=base_messages$missing_function("J"))
2189+
test(715, J(a=1:3,b=4), error="J() called outside of [.data.table. J() is only intended for use in i.")
21902190

21912191
# Test get in j
21922192
DT = data.table(a=1:3,b=4:6)

vignettes/datatable-importing.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ aggr = function (x) {
118118
}
119119
```
120120

121-
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:
121+
The case for `data.table`'s special symbols (e.g. `.SD` and `.N`) and assignment operator (`:=`) is slightly different (see `?.N` for more, including a complete listing of such symbols). 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:
122122

123123
```r
124124
importFrom(data.table, .N, .I, ':=')

0 commit comments

Comments
 (0)