CodeDepends (version 0.5-3)

makeVariableGraph: Create a graph describing the relationships between variables in a script

Description

This creates a graph of nodes and edges describing the relationship of how some variables are used in defining others.

Usage

makeVariableGraph(doc, frags = readScript(doc), info = getInputs(frags),
                   vars = getVariables(info, inputs = free), free = TRUE)

Arguments

doc

the name of the script file

frags

the code fragments from the script as a Script object.

info

the ScriptInfo list of ScriptNodeInfo objects describing each node.

vars

a character vector giving the names of the variables in the scripts. By default, these are the variables defined in the script.

free

a logical value that is passed to getInputs and controls whether we include the free/global variables in the script.

Value

An object of class graphNEL from the graph package.

Details

Note that this collapses variables with the same name into a single node. Therefore, if the code uses the same name for two unrelated variables, there may be some confusion.

See Also

readScript getInputs getVariables

graph Rgraphviz

Examples

Run this code
# NOT RUN {
 u = url("http://www.omegahat.net/CodeDepends/formula.R")
 sc = readScript(u)
 close(u)
 g = makeVariableGraph(, sc)
# }
# NOT RUN {
 f = system.file("samples", "results-multi.R", package = "CodeDepends")
 sc = readScript(f)
 g = makeVariableGraph( info = getInputs(sc))
 if(require(Rgraphviz))
   plot(g)
# }

Run the code above in your browser using DataCamp Workspace