How to recursively make output of a function automatically become input of the same function in R?
<p>I think it is easier to explain my question using a simple example. </p>

<pre><code>Name &lt;- c("A1", "A2")
A &lt;- data.frame(Name)

Name &lt;- c("A11", "A12")
A1 &lt;- data.frame(Name)

Name &lt;- c("A21", "A22")
A2 &lt;- data.frame(Name)

crawl_F &lt;- function(x) { 
   return(x[,1])
 }
crawl_F(A)
</code></pre>

<p>In this example, crawl_F(A) results in A1, A2. However, I want to figure out a way that crawl_F(A) results in A1, A2, A11, A12, A21, A22 with just one call of crawl_F(A). Otherwise, I have to apply the function to A1 and A2 manually in order to get A11, A12, A21, A22. </p>

<p>In the simple case like this, manual apply of the function is not a big deal but if A contains lots of values and each subsequent values has lots of values as well, such manual apply would take enormous time and inefficiency. </p>

<p>I have thought about using recursive function but have not figured out how to write recursion for this probelm. Any ideas with or without using recursion to solve this problem?</p>