Skip to content

Commit

Permalink
class= argument for condition calls (#5914)
Browse files Browse the repository at this point in the history
* 1.15.0 on CRAN. Bump to 1.15.99

* Fix transform slowness (#5493)

* Fix 5492 by limiting the costly deparse to `nlines=1`

* Implementing PR feedbacks

* Added  inside

* Fix typo in name

* Idiomatic use of  inside

* Separating the deparse line limit to a different PR

---------

Co-authored-by: Michael Chirico <[email protected]>

* Improvements to the introductory vignette (#5836)

* Added my improvements to the intro vignette

* Removed two lines I added extra as a mistake earlier

* Requested changes

* Vignette typo patch (#5402)

* fix typos and grammatical mistakes

* fix typos and punctuation

* remove double spaces where it wasn't necessary

* fix typos and adhere to British English spelling

* fix typos

* fix typos

* add missing closing bracket

* fix typos

* review fixes

* Update vignettes/datatable-benchmarking.Rmd

Co-authored-by: Michael Chirico <[email protected]>

* Update vignettes/datatable-benchmarking.Rmd

Co-authored-by: Michael Chirico <[email protected]>

* Apply suggestions from code review benchmarking

Co-authored-by: Michael Chirico <[email protected]>

* remove unnecessary [ ] from datatable-keys-fast-subset.Rmd

* Update vignettes/datatable-programming.Rmd

Co-authored-by: Michael Chirico <[email protected]>

* Update vignettes/datatable-reshape.Rmd

Co-authored-by: Michael Chirico <[email protected]>

* One last batch of fine-tuning

---------

Co-authored-by: Michael Chirico <[email protected]>
Co-authored-by: Michael Chirico <[email protected]>

* Improved handling of list columns with NULL entries (#4250)

* Updated documentation for rbindlist(fill=TRUE)

* Print NULL entries of list as NULL

* Added news item

* edit NEWS, use '[NULL]' not 'NULL'

* fix test

* split NEWS item

* add example

---------

Co-authored-by: Michael Chirico <[email protected]>
Co-authored-by: Michael Chirico <[email protected]>
Co-authored-by: Benjamin Schwendinger <[email protected]>

* clarify that list input->unnamed list output (#5383)

* clarify that list input->unnamed list output

* Add example where make.names is used

* mention role of make.names

* fix subsetting issue in split.data.table (#5368)

* fix subsetting issue in split.data.table

* add a test

* drop=FALSE on inner [

* switch to 3.2.0 R dep (#5905)

* Allow early exit from check for eval/evalq in cedta (#5660)

* Allow early exit from check for eval/evalq in cedta

Done in the browser+untested, please take a second look :)

* Use %chin%

* nocov new code

* frollmax1: frollmax, frollmax adaptive, left adaptive support (#5889)

* frollmax exact, buggy fast, no fast adaptive

* frollmax fast fixing bugs

* frollmax man to fix CRAN check

* frollmax fast adaptive non NA, dev

* froll docs, adaptive left

* no frollmax fast adaptive

* frollmax adaptive exact NAs handling

* PR summary in news

* copy-edit changes from reviews

Co-authored-by: Benjamin Schwendinger <[email protected]>

* Apply suggestions from code review

Co-authored-by: Michael Chirico <[email protected]>
Co-authored-by: Benjamin Schwendinger <[email protected]>

* comment requested by Michael

* update NEWS file

* Apply suggestions from code review

Co-authored-by: Michael Chirico <[email protected]>

* Apply suggestions from code review

Co-authored-by: Michael Chirico <[email protected]>

* add comment requested by Michael

* add comment about int iterator for loop over k-1 obs

* extra comments

* Revert "extra comments"

This reverts commit 03af0e3.

* add comments to frollmax and frollsum

* typo fix

---------

Co-authored-by: Michael Chirico <[email protected]>
Co-authored-by: Benjamin Schwendinger <[email protected]>

* Friendlier error in assignment with trailing comma (#5467)

* friendlier error in assignment with trailing comma

e.g. `DT[, `:=`(a = 1, b = 2,)`.

WIP. Need to add tests and such, but editing from browser before I forget.

* Another pass

* include unnamed indices on RHS too

* tests

* NEWS

* test numbering

* explicit example in NEWS

* Link to ?read.delim in ?fread to give a closer analogue of expected behavior (#5635)

* fread is similar to read.delim (#5634)

* Use ?read.csv / ?read.delim

---------

Co-authored-by: Michael Chirico <[email protected]>
Co-authored-by: Michael Chirico <[email protected]>

* Run GHA jobs on 1-15-99 dev branch (#5909)

* Make declarations static for covr (#5910)

* class= argument for condition calls

* Unify logic with helper

* Add tests

* Use call.=FALSE where possible

* correct caught class

* strip call=/call.= handling

* botched merge

---------

Co-authored-by: Ofek <[email protected]>
Co-authored-by: Ani <[email protected]>
Co-authored-by: David Budzynski <[email protected]>
Co-authored-by: Scott Ritchie <[email protected]>
Co-authored-by: Benjamin Schwendinger <[email protected]>
Co-authored-by: Jan Gorecki <[email protected]>
Co-authored-by: Benjamin Schwendinger <[email protected]>
Co-authored-by: Manuel López-Ibáñez <[email protected]>
  • Loading branch information
9 people authored Apr 20, 2024
1 parent 8ae1b2d commit d420afe
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
30 changes: 22 additions & 8 deletions R/translation.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@ catf = function(fmt, ..., sep=" ", domain="R-data.table") {
cat(gettextf(fmt, ..., domain=domain), sep=sep)
}

stopf = function(fmt, ..., domain="R-data.table") {
stop(gettextf(fmt, ..., domain=domain), domain=NA, call. = FALSE)
raise_condition = function(signal, message, classes, immediate=FALSE, appendLF=FALSE) {
obj = list(message=message, call=sys.call(2))
# NB: append _after_ translation
if (appendLF) obj$message = paste0(obj$message, "\n")
setattr(obj, "class", classes)
# cannot set immediate.=TRUE through warning(), so use the description in ?warning to replicate this behavior ourselves. tested manually.
if (immediate) {
old = options(warn=1)
on.exit(options(old))
}
signal(obj)
}

warningf = function(fmt, ..., immediate.=FALSE, noBreaks.=FALSE, domain="R-data.table") {
warning(gettextf(fmt, ..., domain=domain), domain=NA, call.=FALSE, immediate.=immediate., noBreaks.=noBreaks.)
stopf = function(fmt, ..., class=NULL, domain="R-data.table") {
raise_condition(stop, gettextf(fmt, ..., domain=domain), c(class, "simpleError", "error", "condition"))
}

messagef = function(fmt, ..., appendLF=TRUE, domain="R-data.table") {
message(gettextf(fmt, ..., domain=domain), domain=NA, appendLF=appendLF)
warningf = function(fmt, ..., immediate.=FALSE, class=NULL, domain="R-data.table") {
raise_condition(warning, gettextf(fmt, ..., domain=domain), c(class, "simpleWarning", "warning", "condition"), immediate=immediate.)
}

packageStartupMessagef = function(fmt, ..., appendLF=TRUE, domain="R-data.table") {
packageStartupMessage(gettextf(fmt, ..., domain=domain), domain=NA, appendLF=appendLF)
messagef = function(fmt, ..., appendLF=TRUE, class=NULL, domain="R-data.table") {
raise_condition(message, gettextf(fmt, ..., domain=domain), c(class, "simpleMessage", "message", "condition"), appendLF=appendLF)
}

packageStartupMessagef = function(fmt, ..., appendLF=TRUE, class=NULL, domain="R-data.table") {
# NB: packageStartupMessage() itself calls message(.packageStartupMessage(...))
messagef(fmt, ..., appendLF=appendLF, class=c(class, "packageStartupMessage"), domain=domain)
}
27 changes: 27 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ if (exists("test.data.table", .GlobalEnv, inherits=FALSE)) {
isRealReallyInt = data.table:::isRealReallyInt
is_utc = data.table:::is_utc
melt.data.table = data.table:::melt.data.table # for test 1953.4
messagef = data.table:::messagef
null.data.table = data.table:::null.data.table
packageStartupMessagef = data.table:::packageStartupMessagef
print.data.table = data.table:::print.data.table
replace_dot_alias = data.table:::replace_dot_alias
rollup.data.table = data.table:::rollup.data.table
Expand All @@ -66,9 +68,11 @@ if (exists("test.data.table", .GlobalEnv, inherits=FALSE)) {
.shallow = data.table:::.shallow
split.data.table = data.table:::split.data.table
if (!exists('startsWith', 'package:base', inherits=FALSE)) startsWith = data.table:::startsWith
stopf = data.table:::stopf
test = data.table:::test
uniqlengths = data.table:::uniqlengths
uniqlist = data.table:::uniqlist
warningf = data.table:::warningf
which_ = data.table:::which_
which.first = data.table:::which.first
which.last = data.table:::which.last
Expand Down Expand Up @@ -18499,3 +18503,26 @@ test(2258.9, capture.output(print(DT, na.print=".", topn=2)), c(" x", " 1: ."
x = data.table(rep(1:2, each=5L), 1:5, 1:10)
test(2259.1, names(split(x, by = c("V1", "V2"), sep = "|")), sort(names(split(x, list(x$V1, x$V2), sep = "|"))))
test(2259.2, names(split(x, by = c("V1", "V2"), sep = "||")), sort(names(split(x, list(x$V1, x$V2), sep = "||"))))

# custom signaling functions
## basics: default signals with/without formats
test(2260.01, tryCatch(stopf("%s", "abc"), error=function(x) conditionMessage(x)), "abc")
test(2260.02, tryCatch(stopf("abc"), error=function(x) conditionMessage(x)), "abc")
test(2260.03, tryCatch(warningf("%s", "abc"), warning=function(x) conditionMessage(x)), "abc")
test(2260.04, tryCatch(warningf("abc"), warning=function(x) conditionMessage(x)), "abc")
test(2260.05, tryCatch(messagef("%s", "abc"), message=function(x) conditionMessage(x)), "abc\n")
test(2260.06, tryCatch(messagef("abc"), message=function(x) conditionMessage(x)), "abc\n")
test(2260.07, tryCatch(messagef("abc", appendLF=FALSE), message=function(x) conditionMessage(x)), "abc")
test(2260.08, tryCatch(packageStartupMessagef("%s", "abc"), packageStartupMessage=function(x) conditionMessage(x)), "abc\n")
test(2260.09, tryCatch(packageStartupMessagef("abc"), packageStartupMessage=function(x) conditionMessage(x)), "abc\n")
test(2260.10, tryCatch(packageStartupMessagef("abc", appendLF=FALSE), packageStartupMessage=function(x) conditionMessage(x)), "abc")

## custom signal classes
test(2260.11, inherits(tryCatch(stopf("x", class="test_error"), condition=identity), "test_error"))
test(2260.12, inherits(tryCatch(stopf("x", class="test_error"), condition=identity), "error"))
test(2260.13, inherits(tryCatch(warningf("x", class="test_warning"), condition=identity), "test_warning"))
test(2260.14, inherits(tryCatch(warningf("x", class="test_warning"), condition=identity), "warning"))
test(2260.15, inherits(tryCatch(messagef("x", class="test_message"), condition=identity), "test_message"))
test(2260.16, inherits(tryCatch(messagef("x", class="test_message"), condition=identity), "message"))
test(2260.17, inherits(tryCatch(packageStartupMessagef("x", class="test_psm"), condition=identity), "test_psm"))
test(2260.18, inherits(tryCatch(packageStartupMessagef("x", class="test_psm"), condition=identity), "packageStartupMessage"))

0 comments on commit d420afe

Please sign in to comment.