trace. purr::walk, , sapply .
3 , 50:
myfun1 <- function(){ x <- 1 ; stop( "error here" ) }
myfun2 <- function(){ x <- 2 ; banana(2) }
myfun3 <- function(){ x <- 3 ; x <- "potatoe" + x }
myfun1()
myfun2()
myfun3()
, x :
funs <- c("myfun1","myfun2","myfun3")
purrr::walk(funs,trace,exit = quote(print( x )))
myfun1()
# Error in myfun1() : error here
# Tracing myfun1() on exit
# [1] 1
myfun2()
# Error in myfun2() : could not find function "banana"
# Tracing myfun2() on exit
# [1] 2
myfun3()
# Error in "potatoe" + x : non-numeric argument to binary operator
# Tracing myfun3() on exit
# [1] 3
:
purrr::walk(funs,untrace)
x ,
myfun4 <- function(){ x <- 4 ; TRUE }
trace(myfun4, exit = quote(print( x )))
myfun4()
Tracing myfun4() on exit
[1] 4
[1] TRUE
x , , , print FALSE , . x:
untrace(myfun4)
funs <- c("myfun1","myfun2","myfun3","myfun4")
purrr::walk(funs,trace, print=FALSE,exit=quote(
if(exists(".Traceback") && .Traceback[[length(.Traceback)]] == sys.calls()[[1]]){
message("x at time of error:")
print(x)}))
myfun3()
myfun4()