MyNixOS website logo
Description

Graph the Relationship Between Functions in an R Package.

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.

pkgGraphR

CRANstatus Lifecycle:stable Static Badge

Use Case

When developing large packages or Shiny apps in R, it can be difficult to track where a modification to one function might propagate down-stream. As a simple example, suppose you've moved from the initial prototype phase into a more serious development phase for a package and realize that you would like to change parameter names in a function from some.param to someParam in order to match other function parameterization. This function might live in the utils.R file and be called by functions spread out across several other .R files. Having a map (graph) of what functions depend on this function can be very helpful in making sure that all usages of this function get adjusted correctly.

As this package is specifically intended for development phase, it doesn't require the package to be built and in fact works with any directory containing R files, or even a single '.R' file. This has the advantage of being useful outside of R package development, specifically in cases such as shiny apps which are often developed outside of the package context.

Install

install.packages("pkgGraphR") or devtools::install_gitlab("doliv071/pkggraphr")

Usage

There are 2 (or 3) steps to using pkgGraphR, first (optional) collect the function assignments with collectFunNames, next build the graph object (a list containing nodes and edges) with buildPackageGraph, finally visualize the results as desired with plotPackageGraph. The example below shows how to use each function assuming you are in the package or app directory you want to visualize.

library(pkgGraphR)

funclist <- collectFunNames(x = ".")
funcgraph <- buildPackageGraph(x = ".", 
                               unique.edges = TRUE, 
                               only.connected = FALSE)
# under default parameters, only the graph is required
plotPackageGraph(graph = funcgraph)
# alternatively, plot with grouping and/or coloring (requires fun.list)
plotPackageGraph(graph = funcgraph, 
                 fun.list = funclist, 
                 use.colors = T)
plotPackageGraph(graph = funcgraph, 
                 fun.list = funclist, 
                 use.subgraphs = T)
plotPackageGraph(graph = funcgraph, 
                 fun.list = funclist, 
                 use.subgraphs = T, 
                 use.colors = T)

{width=24% height=250px} {width=24% height=250px} {width=24% height=250px} {width=24% height=250px}

Known "issues"

There are a few known issues which should be taken into consideration.

  • grViz doesn't allow . in node names so if you use my.function be aware that grViz will show these as myfunction.
  • The use.colors parameter does not come with a legend, which isn't ideal.
  • Very large packages (e.g. dplyr) will be difficult to visualize. As a workaround, you can use htmlwidgets and webshot to generate a high resolution pdf as below.
p <- plotPackageGraph(graph = funcgraph)
htmlwidgets::saveWidget(p, "test.html")
webshot::webshot(url = "test.html", file = "test.pdf")

Metadata

Version

0.3.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows