recursiveCalls computes the result of a recursive function call and prints all recursive calls

recursiveCalls(recFunc, ...)

Arguments

...

the parameters of the function to be called

recfunc:

the recursive function to be called without the parenthesis or the arguments; must have at least one recursive function call

Value

the result of calling the input function with the given parameters

Details

This function takes a recursive function and its parameters and returns the result of that function call and also prints all recursive calls. Useful for checking for errors in recursive functions.

Examples

recursiveCalls(fib,5)
#> [1] "fib(5)" #> [1] "fib(4)" #> [1] "fib(3)" #> [1] "fib(2)" #> [1] "fib(1)" #> [1] "fib(0)" #> [1] "fib(1)" #> [1] "fib(2)" #> [1] "fib(1)" #> [1] "fib(0)" #> [1] "fib(3)" #> [1] "fib(2)" #> [1] "fib(1)" #> [1] "fib(0)" #> [1] "fib(1)"
#> [1] 5