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

class= argument for condition calls #5914

Merged
merged 30 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e4324cf
1.15.0 on CRAN. Bump to 1.15.99
MichaelChirico Jan 6, 2024
18a7209
Fix transform slowness (#5493)
OfekShilon Jan 6, 2024
b6bd964
Improvements to the introductory vignette (#5836)
Anirban166 Jan 6, 2024
68f0e41
Vignette typo patch (#5402)
davidbudzynski Jan 6, 2024
7e1a950
Improved handling of list columns with NULL entries (#4250)
sritchie73 Jan 7, 2024
d9d17a7
clarify that list input->unnamed list output (#5383)
MichaelChirico Jan 8, 2024
da24f85
fix subsetting issue in split.data.table (#5368)
MichaelChirico Jan 8, 2024
58608a2
switch to 3.2.0 R dep (#5905)
MichaelChirico Jan 12, 2024
c84a123
Allow early exit from check for eval/evalq in cedta (#5660)
MichaelChirico Jan 12, 2024
513f20f
frollmax1: frollmax, frollmax adaptive, left adaptive support (#5889)
jangorecki Jan 12, 2024
daee139
Friendlier error in assignment with trailing comma (#5467)
MichaelChirico Jan 14, 2024
f5ef168
Link to ?read.delim in ?fread to give a closer analogue of expected b…
MLopez-Ibanez Jan 13, 2024
f658ff4
Run GHA jobs on 1-15-99 dev branch (#5909)
MichaelChirico Jan 14, 2024
a56b796
Make declarations static for covr (#5910)
MichaelChirico Jan 15, 2024
8ca0e0a
class= argument for condition calls
MichaelChirico Jan 15, 2024
b548ab2
Unify logic with helper
MichaelChirico Jan 15, 2024
c1ce071
Add tests
MichaelChirico Jan 16, 2024
ef538c2
Use call.=FALSE where possible
MichaelChirico Jan 16, 2024
adaf7ea
correct caught class
MichaelChirico Jan 16, 2024
7c199c5
strip call=/call.= handling
MichaelChirico Jan 16, 2024
4dbeeb2
Merge branch 'master' into condition-signals
MichaelChirico Feb 19, 2024
d7575c3
botched merge
MichaelChirico Feb 19, 2024
6e13511
Merge branch 'master' into condition-signals
MichaelChirico Feb 19, 2024
3172779
Merge branch 'master' into condition-signals
MichaelChirico Mar 8, 2024
cb61ff7
Merge branch 'master' into condition-signals
MichaelChirico Apr 4, 2024
f18ce75
Merge remote-tracking branch 'origin/condition-signals' into conditio…
MichaelChirico Apr 4, 2024
4035f61
Merge branch 'master' into condition-signals
MichaelChirico Apr 4, 2024
25e524b
Merge branch 'master' into condition-signals
MichaelChirico Apr 9, 2024
f290c38
Merge remote-tracking branch 'origin/condition-signals' into conditio…
MichaelChirico Apr 9, 2024
4624817
Merge branch 'master' into condition-signals
MichaelChirico Apr 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
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"))
Loading