diff w4mcorcov_util.R @ 11:ddcc33ff3205 draft

planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
author eschen42
date Wed, 05 Sep 2018 22:31:21 -0400
parents 50f60f94c034
children
line wrap: on
line diff
--- a/w4mcorcov_util.R	Sat Sep 01 11:33:03 2018 -0400
+++ b/w4mcorcov_util.R	Wed Sep 05 22:31:21 2018 -0400
@@ -21,10 +21,54 @@
   return (retval)
 }
 
+errorSink <- function(which_function, ...) {
+  var_args <- "..."
+  tryCatch(
+    var_args <<- (deparse(..., width.cutoff = 60))
+  , error = function(e) {print(e$message)}
+  )
+  if (var_args == "...")
+    return
+  # format error for logging
+  format_error <- function(e) {
+    sprintf(
+      "Error\n{  message: %s\n, arguments: %s\n}\n"
+    , e$message
+    , Reduce(f = paste, x = var_args)
+    )
+  }
+  format_warning <- function(e) {
+    sprintf(
+      "Warning\n{  message: %s\n, arguments: %s\n}\n"
+    , e$message
+    , Reduce(f = paste, x = var_args)
+    )
+  }
+  sink_number <- sink.number()
+  sink(stderr())
+  tryCatch(
+    var_args <- (deparse(..., width.cutoff = 60))
+  , expr = {
+      retval <- which_function(...)
+    }
+    , error = function(e) cat(format_error(e), file = stderr())
+    , warning = function(w) cat(format_warning(w), file = stderr())
+  )
+  while (sink.number() > sink_number) {
+    sink()
+  }
+}
+errorPrint <- function(...) {
+  errorSink(which_function = print, ...)
+}
+errorCat <- function(...) {
+  errorSink(which_function = cat, ..., "\n")
+}
+
 
 # # pseudo-inverse - computational inverse of non-square matrix a
 # p.i <- function(a) {
 #   solve(t(a) %*% a) %*% t(a)
 # } 
 
-
+# vim: sw=2 ts=2 et ai :