Skip to content

Commit ee99600

Browse files
committed
duplicate error/warn templates for easier translation
1 parent 0e0ce08 commit ee99600

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

R/frollapply.R

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,15 @@ frollapply = function(X, N, FUN, ..., by.column=TRUE, fill=NA, align=c("right","
259259
}
260260
}
261261
## prepare templates for errors and warnings
262-
msg.collect = "frollapply calling parallel::mccollect to collect results from forked processes raised %s.\n%s"
263-
msg.simplify = if (is.function(simplify))
264-
"frollapply completed successfully but raised %s when attempting to simplify results using user specified function in 'simplify' argument. Be sure to provide 'fill' argument matching the type and shape of results returned by the your function. Use simplify=FALSE to obtain a list instead.\n%s"
265-
else if (isTRUE(simplify))
266-
"frollapply completed successfully but raised %s when attempting to simplify results using our internal 'simplifylist' function. Be sure to provide 'fill' argument matching the type and shape of results returned by the your function. Use simplify=FALSE to obtain a list instead. If you believe your results could be automatically simplified please submit your use case as new issue in our issue tracker.\n%s"
262+
err.collect = "frollapply calling parallel::mccollect to collect results from forked processes raised an error.\n%s"
263+
warn.collect = "frollapply calling parallel::mccollect to collect results from forked processes raised a warning.\n%s"
264+
if (is.function(simplify)) {
265+
err.simplify = "frollapply completed successfully but raised an error when attempting to simplify results using user specified function in 'simplify' argument. Be sure to provide 'fill' argument matching the type and shape of results returned by the your function. Use simplify=FALSE to obtain a list instead.\n%s"
266+
warn.simplify = "frollapply completed successfully but raised a warning when attempting to simplify results using user specified function in 'simplify' argument. Be sure to provide 'fill' argument matching the type and shape of results returned by the your function. Use simplify=FALSE to obtain a list instead.\n%s"
267+
} else if (isTRUE(simplify)) {
268+
err.simplify = "frollapply completed successfully but raised an error when attempting to simplify results using our internal 'simplifylist' function. Be sure to provide 'fill' argument matching the type and shape of results returned by the your function. Use simplify=FALSE to obtain a list instead. If you believe your results could be automatically simplified please submit your use case as new issue in our issue tracker.\n%s"
269+
warn.simplify = "frollapply completed successfully but raised a warning when attempting to simplify results using our internal 'simplifylist' function. Be sure to provide 'fill' argument matching the type and shape of results returned by the your function. Use simplify=FALSE to obtain a list instead. If you believe your results could be automatically simplified please submit your use case as new issue in our issue tracker.\n%s"
270+
}
267271

268272
DTths = getDTthreads(FALSE)
269273
use.fork = .Platform$OS.type!="windows" && DTths > 1L
@@ -291,7 +295,7 @@ frollapply = function(X, N, FUN, ..., by.column=TRUE, fill=NA, align=c("right","
291295
for (th in seq_len(ths)) {
292296
jobs[th] = parallel::mcparallel({
293297
#catf("%d\n", 4, "")
294-
# nocov start ## fork processes seem not to be tracked by codecov
298+
# nocov start ## fork processes seem not to be tracked by codecov, at least when parallel not in suggests
295299
setDTthreads(1L) ## disable nested parallelism
296300
lapply(ii[[th]], ## loops over indexes for that thread
297301
FUN = tight, ## handles adaptive and by.column
@@ -305,8 +309,8 @@ frollapply = function(X, N, FUN, ..., by.column=TRUE, fill=NA, align=c("right","
305309
fork.res = withCallingHandlers( ## collect results early to minimize time when user could raise SIGINT
306310
tryCatch(
307311
parallel::mccollect(jobs),
308-
error = function(e) stopf(msg.collect, "an error", e[["message"]]),
309-
warning = function(w) warningf(msg.collect, "a warning", w[["message"]])
312+
error = function(e) stopf(err.collect, e[["message"]]),
313+
warning = function(w) warningf(warn.collect, w[["message"]])
310314
),
311315
interrupt = function(e) {
312316
# nocov start
@@ -367,14 +371,14 @@ frollapply = function(X, N, FUN, ..., by.column=TRUE, fill=NA, align=c("right","
367371
if (is.function(simplify)) {
368372
ans[[thisansi]] = tryCatch(
369373
simplify(ans[[thisansi]]),
370-
error = function(e) stopf(msg.simplify, "an error", e[["message"]]),
371-
warning = function(w) warningf(msg.simplify, "a warning", w[["message"]])
374+
error = function(e) stopf(err.simplify, e[["message"]]),
375+
warning = function(w) warningf(warn.simplify, w[["message"]])
372376
)
373377
} else if (isTRUE(simplify)) {
374378
ans[[thisansi]] = tryCatch(
375379
simplifylist(ans[[thisansi]], fill, ansmask),
376-
error = function(e) stopf(msg.simplify, "an error", e[["message"]]),
377-
warning = function(w) warningf(msg.simplify, "a warning", w[["message"]])
380+
error = function(e) stopf(err.simplify, e[["message"]]),
381+
warning = function(w) warningf(warn.simplify, w[["message"]])
378382
)
379383
}
380384
}

0 commit comments

Comments
 (0)