How does one use `Recall()` to write a recursive function to recursively list directories in a given directory?
This [Question][1] asked about listing directories (not files) in the current directory. I noted in a comment to one of the answers that we can't use the `recursive` argument of functions like `dir` and `list.files` to recursively list directories in the current directory.

The obvious solution to this is to write a recursive function that lists the directories in the current directory that calls itself on each of those directories in turn, and so on, adding to the overall list of directories that gets returned at the end of the recursion.

The `Recall()` function would seem the ideal candidate for this, but I've never really got my head round how one writes a recursive function that adds to the final output each time it is called.

How would one modify this function:

    list.dirs <- function(path) {
        x <- dir(path, full.names = TRUE)
        dnames <- x[file_test("-d", x)]
        dnames
    }

To have it descend recursively through the directories in `dnames` adding any directories it finds to a list of all directories found within the `dnames` directories, and so on...?

  [1]: http://stackoverflow.com/questions/4749783/how-to-obtain-a-list-of-directories-within-a-directory-like-list-files-but-in
How does one use `Recall()` to write a recursive function to recursively list directories in a given directory?
===

This [Question][1] asked about listing directories (not files) in the current directory. I noted in a comment to one of the answers that we can't use the `recursive` argument of functions like `dir` and `list.files` to recursively list directories in the current directory.

The obvious solution to this is to write a recursive function that lists the directories in the current directory that calls itself on each of those directories in turn, and so on, adding to the overall list of directories that gets returned at the end of the recursion.

The `Recall()` function would seem the ideal candidate for this, but I've never really got my head round how one writes a recursive function that adds to the final output each time it is called.

How would one modify this function:

    list.dirs <- function(path) {
        x <- dir(path, full.names = TRUE)
        dnames <- x[file_test("-d", x)]
        dnames
    }

To have it descend recursively through the directories in `dnames` adding any directories it finds to a list of all directories found within the `dnames` directories, and so on...?

  [1]: http://stackoverflow.com/questions/4749783/how-to-obtain-a-list-of-directories-within-a-directory-like-list-files-but-in