The Recall function is used to recursively call a function. That is, suppose we are writing a function called f and we want to call f within itself. Then instead of calling on f within itself, we use the Recall function in its place.
  • arguments – The arguments will correspond to the those of the parent function, i.e. the function that Recall is located within.

Example. We can easily recreate the factorial function in R for integer inputs by making use of the Recall function.
> myFactorial <- function(n){
+   if(n == 1){
+     return(1)
+   } else {
+     return(n*Recall(n-1))
+   }
+ }
> 5*4*3*2*1
[1] 120
> myFactorial(5)
[1] 120
> factorial(5)
[1] 120
Tip. Using the Recall function means nothing needs to be changed within a function if the function name is later changed.

Leave a Reply