3 log_clear <- function() {
4 assign('log_messages',list(),envir=.GlobalEnv)
7 log_add <- function(text,print=T) {
11 assign('log_messages',c(log_messages, text),envir=.GlobalEnv)
14 log_retrieve <- function() {
18 notice <- function(...) {
19 log_add(paste('N:',...))
22 warn <- function(...) {
23 log_add(paste('W:',...))
26 error <- function(...) {
27 log_add(paste('E:',...))
30 fail <- function(...) {
31 txt <- paste('E:',...)
36 log_system <- function(...) {
37 r <- try((function() {
38 # pipe() does not appear useful here, since
39 # we want the return value!
40 # XXX: doesn't work with ; or | !
41 tmp <- tempfile('log_system')
44 # unfortunately this destroys ret
45 #cmd <- paste(cmd,'2>&1','| tee',tmp)
46 cmd <- paste(cmd,'>',tmp,'2>&1')
49 output <- readLines(f)
52 return(list(ret,output))
54 if (inherits(r,'try-error')) {
55 fail('system failed on:',paste(...))
57 log_add(paste('C:',...))
58 for (line in r[[2]]) {
59 if (!length(grep('^[WENI]:',line))) {
60 line = paste('I:',line)
62 log_add(line) #,print=F)