[R] flushing on.exit prior to q()

Benjamin Tyner btyner at gmail.com
Wed Feb 22 00:10:20 CET 2017


Hi,

When using a custom error function that calls q(), what is the 
recommended way to "flush" the calling function's on.exit ?

For example, say I have a script:

    #!/usr/bin/Rscript --no-init-file

    options(error = function() {

       cat("on error message\n", file = stderr())

       q(save = "no", status = 1)
    })

    test <- function() {

        on.exit(cat("on exit message\n", file = stderr()))

        stop("error")
    }

    test()

when I run the script, the "on exit message" does not print. (I found 
one solution might involve adding a stop() to my custom error function 
prior to the q(); however this is somewhat less than ideal: it also 
triggers an "error during wrapup" because of the recursion).

Other ideas, best practices?

Thanks
Ben



More information about the R-help mailing list