Skip to content

Commit

Permalink
Export masks for NSE-only constructs ., J, patterns and `measur…
Browse files Browse the repository at this point in the history
…e` (#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>
  • Loading branch information
3 people authored Jun 20, 2024
1 parent 9be6872 commit fab93a9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
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)
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 @@ -100,6 +100,8 @@

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.
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.
## 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
8 changes: 8 additions & 0 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -2770,6 +2770,14 @@ address = function(x) .Call(Caddress, eval(substitute(x), parent.frame()))
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(":=").')
}

J = function(...) {
stopf("J() called outside of [.data.table. J() is only intended for use in i.")
}

. = function(...) {
stopf(".() called outside of [.data.table. .() is only intended as an alias for list() inside DT[...].")
}

let = function(...) `:=`(...)

setDF = function(x, rownames=NULL) {
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="J() called outside of [.data.table. J() is only intended for use in i.")

# 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 (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:

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

0 comments on commit fab93a9

Please sign in to comment.