knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

CRAN status Travis build status AppVeyor build status

library(pkgattrs)
library(tidyverse)

pkgattrs

The pkgattrs package is useful for getting information on the contents of any R package. One of the things that can be done is generating a summary of functions available in one or more packages. We can conveniently do this using the pkgattrs() function. Here is an example where we can create an informative table of the functions in the pkgattrs and blastula packages (hosted on GitHub).

fn_info <-
  pkgattrs(
    from_github("rich-iannone/pkgattrs"),
    from_github("rich-iannone/blastula")
  )

The resulting tibble contains the following information in each record:

fn_info

The package also supplies functions for visualizing the relationships between a package's functions as a network graph. For example, we could obtain a function information tibble for the stationary package, transform that to a graph, and then examine this network with the function_graph_all() function.

pkgattrs(from_github("rich-iannone/stationary")) %>%
  function_graph_all()

In this graph, the green nodes show the functions that are exported, and, the relative sizing of nodes is scaled the number of package functions called by each. Each edge represents the relationship called_in.

We can also focus on a subgraph with a single function. The function function_graph_single() can be used with the function graph object, taking a function name to show all the package functions that the function calls. In the following example, we can examine which functions are called by the print.ptblank_agent() method.

pkgattrs(from_github("rich-iannone/pointblank")) %>%
  function_graph_single(target_fn = "print.ptblank_agent")

Finally, the package has a means to write out a given package's API with the write_pkg_api() function. For the pkgattrs package (this package), we can generate a file that lists the exported functions along with each of the function arguments and default values.

write_pkg_api(filename = "pkg_api")

This example generates the following text in the API file:

from_github(repo)
function_graph_all(pkgattrs_tbl, pkg_name = NULL)
function_graph_single(pkgattrs_tbl, target_fn, pkg_name = NULL)
pkg_api(...)
pkgattrs(..., .make_clean = TRUE, .get_cyclocomp = FALSE)
write_pkg_api(..., filename = "pkg_api")

Installation

You can install pkgattrs from GitHub with:

devtools::install_github("rich-iannone/pkgattrs")


rich-iannone/pkgattrs documentation built on July 28, 2020, 7:42 p.m.