Displaying 20 results from an estimated 40 matches for "invokerestart".
2012 Sep 11
1
Is invokeRestart("abort") unstoppable?
Hi,
I'm trying to implement an abort() method that works just like stop()
but does not signal the condition such that try() and tryCatch(...,
condition=...) are, contrary to stop(), effectively non-working with
abort() calls.
In order to achieve this, I stumbled upon invokeRestart("abort"), cf.
help("invokeRestart", package="base") that reads "Restarts are used
for establishing recovery protocols. They can be established using
withRestarts. One pre-established restart is an abort restart that
represents a jump to top level.".
So, my c...
2018 Jul 28
4
re-throwing an interrupt condition
Anyone knows a way to re-throw a caught interrupt condition, so that
it behaves just like the original one? I.e. no error message is
printed, but the execution is stopped of course. With just calling
stop in the error handler, it prints the error message, or, if there
is no error message (like in the original interrupt condition),
another error happens.
tryCatch(Sys.sleep(100), interrupt =
2012 Oct 21
1
suppress *specific* warnings?
...isn't
helping me ... ?)
suppressWarnings2 <- function(expr,regex=NULL) {
opts <- options(warn = -1)
on.exit(options(opts))
withCallingHandlers(expr, warning = function(w) {
## browser()
if (is.null(regex) || grepl(w[["message"]],regex)) {
invokeRestart("muffleWarning")
} else {
## ? what do I here to get the warning issued?
## browser()
## computeRestarts() shows "browser",
## "muffleWarning", and "abort" ...
options(opts)
wa...
2004 Mar 11
2
No traceback available when using try(...)
Hello,
1. The Situation :
------------------------
The stack traceback is not available when error ouccured in a try(....)
-- test.R --------------------------------
f<-function(a){
return ( log(a) )
}
try(f("A"))
traceback()
-------------------------------------------
I get the following message :
> try(f("A"))
Error in log(x) : Non-numeric argument to mathematical
2010 Dec 05
1
How to catch both warnings and errors?
...rg/msg81380.html
f <- function(x){
## warnings
w.list <- NULL # init warning
w.handler <- function(w){ # warning handler
warn <- simpleWarning(w$message, w$call) # build warning
w.list <<- c(w.list, paste(warn, collapse = " ")) # save warning
invokeRestart("muffleWarning")
}
## errors
e.list <- NULL # init errors
e.handler <- function(e){ # error handler
err <- simpleError(e$message, e$call)
e.list <<- c(e.list, paste(err, collapse = " ")) # save error
}
## execute command
res <-...
2019 Feb 24
1
stopifnot
...39;stopifnot', 'eval' is used only in handling stopifnot(exprs=) . The warning message from
stopifnot(exprs={warning()})
has 'eval' call:
In eval(cl.i, envir = envir) :
This may work.
withCallingHandlers(<something>,
warning = function(w) {
w$call <- cl.i; warning(w); invokeRestart("muffleWarning") })
Current documentation says:
Since R version 3.5.0, expressions are evaluated sequentially, and hence evaluation stops as soon as there is a "non-TRUE", asnindicated by the above conceptual equivalence statement. Further, when such an expression signals an e...
2018 Jul 26
2
Possible bug: R --slave --interactive stdin echo on Linux when stdin is a fifo
...is that windows does not have --interactive. Is there a
> way to run R
> 1) without echoing stdin, and
I'm not seeing an echo for your example on Ubuntu or Fedora.
> 2) without quitting on the first error,
> on all platforms?
One option is to use
options(error = function() invokeRestart("abort"))
There may be better ways.
Best,
luke
>
> Gabor
>
>> Barry
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
Luke Tierney
Ralph E. Wareham Professor o...
2018 Jul 28
0
re-throwing an interrupt condition
The internal code does more or less
signalCondition(e) ## allows for (another) handler
cat("\n") ## cleans up console
invokeRestart("abort") ## jump to 'abort' restart if not handled
[for back compatibility it also runs the error option code if that is
set, but that may go away eventually].
A version of your example:
> {
+ tryCatch(Sys.sleep(100),
+ interrupt = function(e) {
+...
2012 Jan 11
0
Problem concerning withRestarts and R2WinBUGS
...t my code to continue untill I get 1000 succesful replications, and ignore the replications that failed. I figured I might be able to do so by putting the data generation and analysis steps in a second function embedded in the overall one, and calling this second function using the withRestarts and invokeRestart options, but I can´t get this to work. Can somebody help me figure this out by telling me if this is even possible, and if so, how withRestarts and invokeRestarts should be called to do this? Alternatively, if any of you know an other way to aqcuire the desired effect I´m also very interested.
K...
2012 Feb 03
1
Resume processing after warning handler.
Dear list!
I have a script that processes a large number of data files. When one
file fails to process correctly, I want the script to write a message
and to continue with the next file. I achieved this with tryCatch:
for (f in files)
tryCatch({heavy.lifting(f)}, error=function(e) log.error.to.file(e))
I also want to log warning messages and tried something like this:
for (f in
2012 Feb 03
1
GAM (mgcv) warning: matrix not positive definite
...hat capture warnings
Model_n_Warnings <- function(expr) {
localWarnings <- list()
outModel <- withCallingHandlers(expr,
warning = function(w) {
localWarnings[[length(localWarnings)+1]] <<- w$message # store
warning message
invokeRestart("muffleWarning") # avoid printing warning message
to console
})
list(outModel=outModel, warnings=localWarnings)
}
out <- Model_n_Warnings (gam(USE ~ X1 + s(X2) + s(X3), family = binomial,
data = data, method="REML"))
out$warnings
[[1]]
[1] "m...
2015 Sep 10
2
Using IDs to suppress specific messages and warnings
...ges with the IDs provided get muffled. Something like:
suppressMessages <- function (expr, ids = NULL)
{
withCallingHandlers(
expr,
message = function(c)
{
if(is.null(ids) || (inherits(c, "simpleMessage") && c$id %in%
as.character(ids)))
{
invokeRestart("muffleMessage")
}
}
)
}
The hard part is providing IDs for all the existing messages in R and
its packages. It's certainly do-able, but I imagine would take quite
a lot of time.
Is there any enthusiasm for implementing this feature, or something like it?
--
Regards,...
2019 Feb 27
1
stopifnot
...ifnot(exprs=) . The warning message from
? ? > stopifnot(exprs={warning()})
? ? > has 'eval' call:
? ? > In eval(cl.i, envir = envir) :
? ? > This may work.
? ? > withCallingHandlers(<something>,
? ? > warning = function(w) {
? ? > w$call <- cl.i; warning(w); invokeRestart("muffleWarning") })
? ? > Current documentation says:
? ? > Since R version 3.5.0, expressions are evaluated sequentially, and hence evaluation stops as soon as there is a "non-TRUE", asnindicated by the above conceptual equivalence statement. Further, when such an expre...
2019 May 03
1
Strange error messages from parallel::mcparallel family under 3.6.0
...rkTimeout({Sys.sleep(1);TRUE}, timeout=3))
results in sporadic messages of the form:
Error in mcexit(0L) : ignoring SIGPIPE signal
6: selectChildren(jobs, timeout)
5: parallel::mccollect(child, wait = FALSE, timeout = timeout) at
forkTimeout.R#75
4: withCallingHandlers(expr, warning = function(w)
invokeRestart("muffleWarning"))
3: suppressWarnings(parallel::mccollect(child, wait = FALSE, timeout =
timeout)) at forkTimeout.R#75
2: forkTimeout({
Sys.sleep(1)
...
1: print(forkTimeout({
Sys.sleep(1)
...
So, these messages do not appear to prevent the child process from
return...
2019 Jun 21
0
Suggested Patch: Library returns matching installed packages when typo present
...om conditionMessage method is less likely to cause conflicts.
Is it correct that you are proposing something that allows us to do:
registerDefaultConditionHandlers(
packageStartupMessage = function(c) {
## Do something with condition 'c'
...
## Suppress futher processing
invokeRestart("muffleMessage")
}
)
at the core, which avoids having us to wrap up calls in
withCallingHandlers() at top-level calls, e.g.
> withCallingHandlers({
library("foobar"),
}, packageStartupMessage = function(c) {
## Do something with condition 'c'
...
## Suppre...
2019 Jun 21
2
Suggested Patch: Library returns matching installed packages when typo present
Hi Luke,
Thank you for your response.
On 6/21/19 10:56 AM, Tierney, Luke wrote:
Thanks for the suggestion. However I don't think it is the right way
to go. I also don't care for what install.packages() does. Signaling a
warning and then an error means someone has to catch both the error
and the warning, or suppress the warning, in order to handle the error
programmatically.
I do care
2012 May 15
1
KEGGSOAP installation error
...dataPath <- file.path(which.lib.loc, package, "data") env <-
attachNamespace(ns, pos = pos, dataPath = dataPath, deps)})
17: library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return =
TRUE)
18: withCallingHandlers(expr, packageStartupMessage = function(c)
invokeRestart("muffleMessage"))
19: suppressPackageStartupMessages(library(pkg_name, lib.loc = lib,
character.only = TRUE, logical.return = TRUE))
20: doTryCatch(return(expr), name, parentenv, handler)
21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
22: tryCatchList(expr, classes, parentenv...
2013 Jun 07
1
cannot load pbdMPI package after compilation
...r", condition = e))})
13: try({ ns <- loadNamespace(package, c(which.lib.loc, lib.loc))
env <- attachNamespace(ns, pos = pos, deps)})
14: library(pkg_name, lib.loc = lib, character.only = TRUE,
logical.return = TRUE)
15: withCallingHandlers(expr, packageStartupMessage = function(c)
invokeRestart("muffleMessage"))
16: suppressPackageStartupMessages(library(pkg_name, lib.loc = lib,
character.only = TRUE, logical.return = TRUE))
17: doTryCatch(return(expr), name, parentenv, handler)
18: tryCatchOne(expr, names, parentenv, handlers[[1L]])
19: tryCatchList(expr, classes, parentenv...
2015 Sep 10
0
Using IDs to suppress specific messages and warnings
...ng like:
>
> suppressMessages <- function (expr, ids = NULL)
> {
> withCallingHandlers(
> expr,
> message = function(c)
> {
> if(is.null(ids) || (inherits(c, "simpleMessage") && c$id %in%
> as.character(ids)))
> {
> invokeRestart("muffleMessage")
> }
> }
> )
> }
>
> The hard part is providing IDs for all the existing messages in R and
> its packages. It's certainly do-able, but I imagine would take quite
> a lot of time.
>
> Is there any enthusiasm for implementing this...
2018 Jul 26
0
Possible bug: R --slave --interactive stdin echo on Linux when stdin is a fifo
...S:
echo '1+1' | R --slave --interactive
But the FIFO example does not.
Anyway, it seems that if I remove --interactive then I get no echo.
> > 2) without quitting on the first error,
> > on all platforms?
>
> One option is to use
>
> options(error = function() invokeRestart("abort"))
This seems good enough for my use case, thanks much!
Luckily, this also solves the "disabling the crash dialog" problem, which I
have if I specify --interactive.
Gabor
> There may be better ways.
>
> Best,
>
> luke
>
> >
> > Gabor
>...