[R] modify the supposed return value of a function during evaluation?
Jeremie Juste
jeremieju@te @ending from gm@il@com
Fri Sep 14 10:33:53 CEST 2018
Hello,
I'm wondering it is possible and if yes would it be desirable to modify
the return value of functions during evaluation.
I supposed this would be very useful during debugging
myfun <- function(x) {res <- x+3 ; browser() ; res}
let say I run the following function myfun(3) and drop in the browser. I then happened to notice that I should
multiply <x> by 3 instead of adding. I was thinking to do return(x*3)
but the return value is still 6.
> myfun(3)
Called from: myfun(3)
Browse[1]>
debug at #1: res
Browse[2]> return(3*3)
[1] 6
>
This feature could be valuable if the following setting
function(){
tmp_res <- time_consuming_function_with_browser(param)
some_other_function(tmp_res)
}
Best regards,
Jeremie
More information about the R-help
mailing list