Explore Nested Functions

Many times a function will contain another function definition, these will not always be very readable in the body of the main function. {flow} offers a way to visualize those.

When using flow on the main function, a message will signify what nested functions can be viewed. The base function bquote is a good example.

library(flow)
flow_view(bquote)
#> We found function definitions in this code, use the argument nested_fun to inspect them
#> $unquote
#> function(e) {
#>     if (is.pairlist(e)) 
#>         as.pairlist(lapply(e, unquote))
#>     else if (is.call(e)) {
#>         if (is.name(e[[1L]]) && as.character(e[[1]]) == ".") 
#>             eval(e[[2L]], where)
#>         else if (splice) {
#>             if (is.name(e[[1L]]) && as.character(e[[1L]]) == 
#>                 "..") 
#>                 stop("can only splice inside a call", call. = FALSE)
#>             else as.call(unquote.list(e))
#>         }
#>         else as.call(lapply(e, unquote))
#>     }
#>     else e
#> }
#> 
#> $is.splice.macro
#> function(e) is.call(e) && is.name(e[[1L]]) && as.character(e[[1L]]) == 
#>     ".."
#> 
#> $unquote.list
#> function(e) {
#>     p <- Position(is.splice.macro, e, nomatch = NULL)
#>     if (is.null(p)) 
#>         lapply(e, unquote)
#>     else {
#>         n <- length(e)
#>         head <- if (p == 1) 
#>             NULL
#>         else e[1:(p - 1)]
#>         tail <- if (p == n) 
#>             NULL
#>         else e[(p + 1):n]
#>         macro <- e[[p]]
#>         mexp <- eval(macro[[2L]], where)
#>         if (!is.vector(mexp) && !is.expression(mexp)) 
#>             stop("can only splice vectors")
#>         c(lapply(head, unquote), mexp, as.list(unquote.list(tail)))
#>     }
#> }

We can then inspect those by using the nested_fun argument, with a numeric id or a name (if unambiguous)

flow_view(bquote, nested_fun = "unquote")
flow_view(bquote, nested_fun = 3)