Package 'pkgGraphR'

Title: Graph the Relationship Between Functions in an R Package
Description: It is often useful when developing an R package to track the relationship between functions in order to appropriately test and track changes. This package generates a graph of the relationship between all R functions in a package. It can also be used on any directory containing .R files which can be very useful for 'shiny' apps or other non-package workflows.
Authors: David Oliver [aut, cre, cph]
Maintainer: David Oliver <[email protected]>
License: GPL (>= 3)
Version: 0.2.0
Built: 2024-10-31 03:04:29 UTC
Source: https://gitlab.com/doliv071/pkggraphr

Help Index


Build a graph of an R package or directory

Description

Generates the Nodes and Edges of a set of functions in an R package or directory

Usage

buildPackageGraph(x, unique.edges = TRUE, only.connected = FALSE)

Arguments

x

A character string specifying the path to an R package or directory

unique.edges

Logical indicating whether there should be only a single edge between nodes. DEFAULT: TRUE

only.connected

Logical indicating whether unconnected nodes should be removed from the graph. DEFAULT: FALSE

Value

A named list of length 2 containing a character vector of nodes and a data.frame of edges.

Examples

system.file("extdata", package = "pkgGraphR") |> 
    buildPackageGraph()

Collect all functions in a package or directory

Description

collect all the functions defined in an R program, directory, or file

Usage

collectFunNames(x)

Arguments

x

A character string specifying the path to an R package, directory, or file

Value

A named list of function assignments in each '.R' file in 'x'

Examples

system.file("extdata", package = "pkgGraphR") |> 
    collectFunNames()

Plot a graph or diagram of a package

Description

From a list of nodes and edges, plots a diagram or graph

Usage

plotPackageGraph(graph, fun.list, use.subgraphs = FALSE, use.colors = FALSE)

Arguments

graph

A list generated by buildPackageGraph containing edges and nodes of the graph.

fun.list

An optional list generated by collectFunNames containing each files function assignments. Used only if 'use.subgraphs' or 'use.colors' are true

use.subgraphs

Logical indicating whether the graph should be partitioned into subgraphs by the file in which the function assignment was made. DEFAULT: FALSE

use.colors

Logical indicating whether the nodes of the graph should be colored by the file in which the function assignment was made. N.B. No legend is plotted for the colors. DEFAULT: FALSE

Value

A grviz plot.

See Also

collectFunNames, buildPackageGraph

Examples

pkgGraph <- system.file("extdata", package = "pkgGraphR") |> 
    buildPackageGraph()
plotPackageGraph(graph = pkgGraph)

pkgFuns <- system.file("extdata", package = "pkgGraphR") |> 
    collectFunNames()

plotPackageGraph(graph = pkgGraph, fun.list = pkgFuns, use.subgraphs = TRUE)
plotPackageGraph(graph = pkgGraph, fun.list = pkgFuns, use.colors = TRUE)
plotPackageGraph(graph = pkgGraph, fun.list = pkgFuns, use.colors = TRUE, use.subgraphs = TRUE)