rm(list = ls())
require(kaiaulu)
require(stringi)
require(visNetwork)
require(igraph)
require(data.table)
require(knitr)

1 Specify Folder Path

This Notebook does not currently use the project configuration file since it is on early stage. We can specify any folder here:

folder_path <- "../../rawdata/git_repo/codeface/codeface/R"

2 Dependency Networks

The parse_r_dependencies function will then look recursively for every .R or .r files and use R abstract syntax tree to identify, per file, what is the caller function (origin), and what function it calls (destination). Since we have the file information where the functions are defined, we can generate either a file or a function network. A sample of the table is as such:

dependencies <- parse_r_dependencies(folder_path)
head(dependencies)
##    src_functions_call_name src_functions_call_filename
## 1:       tstamp.to.POSIXct                     utils.r
## 2:       tstamp.to.POSIXct                     utils.r
## 3:       tstamp.to.POSIXct                     utils.r
## 4:  compute.next.timestamp                analyse_ts.r
## 5:   get.commits.by.ranges                     query.r
## 6:             trim.series                  ts_utils.r
##    src_functions_caller_name src_functions_caller_filename
## 1:     get.series.boundaries                  analyse_ts.r
## 2:     get.series.boundaries                  analyse_ts.r
## 3:     get.series.boundaries                  analyse_ts.r
## 4:         make.index.unique                  analyse_ts.r
## 5:               gen.full.ts                  analyse_ts.r
## 6:               gen.full.ts                  analyse_ts.r
##    src_line_functions_call_start src_line_functions_call_end
## 1:                            48                          48
## 2:                            49                          49
## 3:                            52                          52
## 4:                            90                          90
## 5:                           107                         107
## 6:                           117                         117

2.1 File Network

file_graph <- transform_r_dependencies_to_network(dependencies,dependency_type="file")
project_function_network <- igraph::graph_from_data_frame(d=file_graph[["edgelist"]], 
                      directed = TRUE,
                      vertices = file_graph[["nodes"]])
visIgraph(project_function_network,randomSeed = 1)

2.2 Function Network

function_graph <- transform_r_dependencies_to_network(dependencies,dependency_type="function")
project_function_network <- igraph::graph_from_data_frame(d=function_graph[["edgelist"]], 
                      directed = TRUE,
                      vertices = function_graph[["nodes"]])
visIgraph(project_function_network,randomSeed = 1)