rdependenciesr-package

R {flow} flow_view_dependencies does not work with non-package structure


I started collaborating on a new, large R project. I want to get an idea of how various functions relate to each other using {flow} and flow_view_deps(). There is an R/functions folder where all functions are defined. I loaded all the functions into the global environment and tried to use flow_view_deps()

However, when I call flow_view_deps(), it throws an error about the lack of a DESCRIPTION file. The project is not and will not be a package, so there is no way for me to convert it into a package to make it work. I tried to follow issues https://github.com/moodymudskipper/flow/issues/88 and https://github.com/moodymudskipper/flow/issues/138, but it seems it still expects a package.

Is there a way to get flow_view_deps() to work with a number of functions defined in a folder / global environment without making a package?

Below is a simple code that reproduces the issue:

library(flow)
foo <- function(x) paste0("test", x)
bar <- function(y) foo(y)

flow_view_deps(bar)

Function flow_view_uses() works fine, but it accepts only a single function, and I'd rather look at all functions together.


Solution

  • Ok, I got it to work with {foodwebr}: https://github.com/lewinfox/foodwebr. After loading all functions into global environment the code below worked nicely.

    library(foodwebr)
    tg <- tidygraph::as_tbl_graph(foodweb())
    
    library(visNetwork)
    
    # Extract nodes and edges from tidygraph object
    nodes <- tg %>% 
      tidygraph::as_tibble() %>% 
      dplyr::mutate(id = row_number(), label = name)
    
    edges <- tg %>% 
      tidygraph::activate("edges") %>% 
      tidygraph::as_tibble() %>%
      dplyr::mutate(
        from = as.integer(from),
        to = as.integer(to)
      )
    
    # Create the interactive network
    vis <- visNetwork(nodes, edges) %>%
      visEdges(arrows = 'to') %>%
      visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE)
    
    htmlwidgets::saveWidget(vis, "function_dependencies.html")