sys.stderr in R - smart1004/r_lan GitHub Wiki

★★★★
https://cran.r-project.org/web/packages/tryCatchLog/vignettes/tryCatchLog-intro.html

https://stackoverflow.com/questions/39964040/r-catch-errors-and-continue-execution-after-logging-the-stacktrace-no-tracebac


tryCatchLog Best Practices

Easiest way to add logging of all conditions Just wrap the call to the main function or main script with tryCatchLog():

library(futile.logger) library(tryCatchLog)

options(keep.source = TRUE) # source code file name and line number tracking options("tryCatchLog.write.error.dump.file" = TRUE) # dump for post-mortem analysis

flog.appender(appender.file("my_app.log")) # to log into a file instead of console flog.threshold(INFO) # TRACE, DEBUG, INFO, WARN, ERROR, FATAL

tryCatchLog(source("your_main_script.R"))


@@@@@@@@@@@@@@ sys.stderr in R

https://stackoverflow.com/questions/1109017/how-do-you-print-to-stderr-in-r

https://github.com/crazyhottommy/phantompeakqualtools/blob/master/run_spp.R

https://www.gastonsanchez.com/r4strings/formatting.html

especifying 'sep'

cat(my_string, "with R", sep=" =) ")
#> programming with data is fun =) with R

#v <- function(...) cat(sprintf(...), sep='', file=stderr())
v <- function(name, age) cat(sprintf("your name: %s your age: %d\n", name, age), sep='', file=stderr())

name <- "ko" age <- 50

v(name, age)

your name: ko your age: 50

http://www.win-vector.com/blog/2012/10/error-handling-in-r/

@@ tryCatchLog
https://cran.r-project.org/web/packages/tryCatchLog/vignettes/tryCatchLog-intro.html