[Rd] traceback {base}: new arguments: file, strip, width

Wolfram Fischer - Z/I/M wolfram@fischer-zim.ch
Tue Feb 4 17:38:02 2003


I propose to add to traceback three new arguments:
- file : filename for output
- strip: strip each line of backtraced code to ``width'' characters
- width: the length of the stripped output text (default 76)

Below you find a proposal for the code changes.

Wolfram



traceback <- function(
#--- NEW ---
	file = "", strip = FALSE, width = 76
#---
){
    if (exists(".Traceback", env = .GlobalEnv)) 
        .Traceback <- get(".Traceback", env = .GlobalEnv)
    else .Traceback <- NULL
    if (is.null(.Traceback) || length(.Traceback) == 0) 
        cat("No traceback available\n")
    else{
		vib.append <- F
        n <- length(.Traceback)
        for (i in 1:n) {
            label <- paste(n - i + 1, ": ", sep = "")
#--- NEW ---
			if( strip ){
				cat( file=file, paste(label, substr( .Traceback[[i]][1]
						, 1, width), sep = "" )
					, sep = "\n", append=vib.append )
			}else{
#---
				if ((m <- length(.Traceback[[i]])) > 1) 
					label <- c(label, rep(substr("          ", 1, 
					  nchar(label)), m - 1))
					cat(
#--- NEW ---
						file=file,
#---
						paste(label, .Traceback[[i]], sep = ""),
						sep = "\n",append=vib.append)
#--- NEW ---
			}
#---
			vib.append <- T
        }
    }
    invisible()
}