| Type: | Package |
| Title: | Get Network Representation of an R Package |
| Version: | 0.5.0 |
| Maintainer: | Brian Burns <brian.burns.opensource@gmail.com> |
| Description: | Tools from the domain of graph theory can be used to quantify the complexity and vulnerability to failure of a software package. That is the guiding philosophy of this package. 'pkgnet' provides tools to analyze the dependencies between functions in an R package and between its imported packages. See the pkgnet website for vignettes and other supplementary information. |
| Imports: | assertthat, covr, data.table, DT, futile.logger, glue,igraph(≥ 1.3), knitr, magrittr, methods, R6, rlang,rmarkdown(≥ 1.9), tools, visNetwork |
| Suggests: | ggplot2, pkgdown, testthat, webshot, withr |
| License: | BSD_3_clause + file LICENSE |
| URL: | https://github.com/uptake/pkgnet,https://uptake.github.io/pkgnet/ |
| BugReports: | https://github.com/uptake/pkgnet/issues |
| RoxygenNote: | 7.3.1 |
| NeedsCompilation: | no |
| Packaged: | 2024-05-03 20:45:00 UTC; brianburns |
| Author: | Brian Burns [aut, cre], James Lamb [aut], Jay Qi [aut] |
| Repository: | CRAN |
| Date/Publication: | 2024-05-03 21:00:02 UTC |
pkgnet : Network Analysis of R Packages
Description
R packages can be complex bodies of code and functionality withhard-to-intuit underlying structure.pkgnet provides tools to analyze andunderstand that structure through the lens ofnetwork theory.
Package Report
The simplest way of using pkgnet is through the functionCreatePackageReport, e.g.,
CreatePackageReport("lubridate")This will create a standalone HTML report containing analyses of variousaspects of the specified subject package.
For more info, check out our introductory vignette with
vignette("pkgnet-intro")Individual Reporters
Reporters are the basic modules of functionality within pkgnet. Eachtype of reporter is used to analyze a particular aspect of the subjectpackage. The currently available reporters are:
DependencyReporteranalyze the recursivenetwork of packages that the subject package depends on.
FunctionReporteranalyze the network ofinterdependencies of the functions defined in the subject package
InheritanceReporteranalyze the classinheritance trees for subject packages that use object-orientedprogramming.
SummaryReporterget an overview of thesubject package through its DESCRIPTION file.
CreatePackageReport uses astandardset of reporters by default. You can customize the reporters you want bypassing in your own list of instantiated reporters, e.g.
CreatePackageReport( "lubridate", pkg_reporters = list(FunctionReporter$new(), InheritanceReporter$new()) )
You can also use reporters interactively. Once you have a reporterinstantiated, check our that reporter's documentation to see what you cando.
reporter <- DependencyReporter$new() reporter$set_package("lubridate")Author(s)
Maintainer: Brian Burnsbrian.burns.opensource@gmail.com
Authors:
James Lambjaylamb20@gmail.com
See Also
Useful links:
Report bugs athttps://github.com/uptake/pkgnet/issues
Base class for Graphs
Description
pkgnet uses R6 classes to define and encapsulate the graphmodels for representing package networks. These classes implementdifferent types of graphs and functionality to calculate their respectivegraph theory measures. The base classAbstractGraph defines thestandard interfaces and functionality.
Currently the only implemented type of graph isDirectedGraph.
Active bindings
nodesnode data.table, read-only.
edgesedge data.table, read-only.
igraphigraph object, read-only.
available_node_measurescharacter vector of all supported node measures. SeeNode Measures section inDirectedGraphMeasures for details about each measure.
available_graph_measurescharacter vector of all supported graph measures. SeeGraph Measures section inDirectedGraphMeasures for details about each measure. Read-only.
default_node_measurescharacter vector of default node measures. SeeNode Measures section inDirectedGraphMeasures for details about each measure.
default_graph_measurescharacter vector of default graph measures. SeeGraph Measures section inDirectedGraphMeasures for details about each measure. Read-only.
Methods
Public methods
Methodnew()
Instantiate new object of the class.
Usage
AbstractGraph$new(nodes, edges)
Arguments
nodesa data.table containing nodes
edgesa data.table containing edges
Returns
Self, invisibly.
Methodnode_measures()
Return specified node-level measures, calculating if necessary.SeeNode Measures section inDirectedGraphMeasures for details about each measure.
Usage
AbstractGraph$node_measures(measures = NULL)
Arguments
measurescharacter vector of measure names. Default NULL will return those that are already calculated.
Returns
a data.table with specified node meaures as columns
Methodgraph_measures()
Return specified graph-level measures, calculating if necessary. SeeGraph Measures section inDirectedGraphMeasures for details about each measure.
Usage
AbstractGraph$graph_measures(measures = NULL)
Arguments
measurescharacter vector of measure names. Default NULL will return those that are already calculated.
Returns
list with specified graph measures.
Methodprint()
print igraph object
Usage
AbstractGraph$print()
Returns
Self, invisibly.
Methodclone()
The objects of this class are cloneable with this method.
Usage
AbstractGraph$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Abstract Network Reporter Class
Description
pkgnet defines several package reporter R6 classes that modela particular network aspect of a package as a graph. These networkreporter classes are extended fromAbstractGraphReporter, whichitself extends theAbstractPackageReporterwith graph-modeling-related functionality.
This article describes the additional fields added by theAbstractGraphReporter class definition.
Super class
pkgnet::AbstractPackageReporter ->AbstractGraphReporter
Active bindings
nodesA data.table, containing information aboutthe nodes of the network the reporter is analyzing. The
nodecolumn acts the identifier. Read-only.edgesA data.table, containing information aboutthe edge connections of the network the reporter is analyzing. Eachrow is one edge, and the columns
SOURCEandTARGETspecify the node identifiers. Read-only.network_measuresA list, containing any measures of the network calculated by the reporter. Read-only.
pkg_grapha graph model object. SeeDirectedGraphfor additional documentation. Read-only.
graph_viza graph visualization object. A
visNetwork::visNetworkobject.Read-only.layout_typea character string, the current layout type for the graph visualization. Can be assigned a new valid layout type value. Use use
grep("^layout_\\S", getNamespaceExports("igraph"), value = TRUE)to see valid options.
Methods
Public methods
Inherited methods
Methodcalculate_default_measures()
Calculates the default node and network measures for this reporter.
Usage
AbstractGraphReporter$calculate_default_measures()
Returns
Self, invisibly.
Methodget_summary_view()
Creates a summary table formatted for display.
Usage
AbstractGraphReporter$get_summary_view()
Returns
ADT object
Methodclone()
The objects of this class are cloneable with this method.
Usage
AbstractGraphReporter$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Abstract Package Reporter
Description
pkgnet defines several package reporter R6 classes that analyze some particular aspect of a package. These reporters share commonfunctionality and interfaces defined by a base reporter classAbstractPackageReporter.
Active bindings
pkg_name(character string) name of set package. Read-only.
report_markdown_path(character string) path to R Markdown template for this reporter. Read-only.
Methods
Public methods
Methodset_package()
Set the package that the reporter will analyze. This can only be done once for a given instance of a reporter. Instantiate a new copy of the reporter if you need to analyze a different package.
Usage
AbstractPackageReporter$set_package(pkg_name, pkg_path = NULL)
Arguments
pkg_name(character string) name of package
pkg_path(character string) optional directory path to source code of the package. It is used for calculating test coverage. It can be an absolute or relative path.
Returns
Self, invisibly.
Methodget_summary_view()
Returns an htmlwidget object that summarizes the analysis of the reporter. Used when creating apackage report.
Usage
AbstractPackageReporter$get_summary_view()
Returns
Self, invisibly.
Methodclone()
The objects of this class are cloneable with this method.
Usage
AbstractPackageReporter$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
pkgnet Analysis Report for an R package
Description
Create a standalone HTML report about a package and its networks.
Usage
CreatePackageReport( pkg_name, pkg_reporters = DefaultReporters(), pkg_path = NULL, report_path = tempfile(pattern = pkg_name, fileext = ".html"))Arguments
pkg_name | (string) name of a package |
pkg_reporters | (list) a list of package reporters |
pkg_path | (string) The path to the package repository. If given, coveragewill be calculated for each function. |
report_path | (string) The path and filename of the output report. Defaultreport will be produced in the temporary directory. |
Value
an instantiatedPackageReport object
pkgnet Report as Vignette
Description
Create pkgnet package report as an R Markdown vignette. Thisvignette can be rendered into a standard HTML vignette with theknitr::rmarkdown vignette engineinto HTML vignettes upon package building. It is also compatible with#'pkgdown sites. See the vignette"Publishing Your pkgnet Package Report" for details about how to use thisfunction, as well asour example for pkgnet.
Usage
CreatePackageVignette( pkg = ".", pkg_reporters = list(DependencyReporter$new(), FunctionReporter$new()), vignette_path = file.path(pkg, "vignettes", "pkgnet-report.Rmd"))Arguments
pkg | (string) path to root directory of package of interest |
pkg_reporters | (list) a list of initialized package reporters |
vignette_path | (string) The location of a file to store the outputvignette file at. Must be an .Rmd file. By default, this will be'<pkg>/vignettes/pkgnet-report.Rmd' relative to the input to pkg |
Default Reporters
Description
Instantiates a list of default reporters to feed intoCreatePackageReport.
Usage
DefaultReporters()Details
Default reporters are:
Note,InheritanceReporter is not included in the default list.
If desired, append a new instance ofInheritanceReporter to theDefaultReporters list.
ex:c(DefaultReporters(), InheritanceReporter$new())
Value
list of instantiated reporter objects
Recursive Package Dependency Reporter
Description
This reporter looks at the recursive network of its dependencieson other packages. This allows a developer to understand how individualdependencies might lead to a much larger set of dependencies, potentiallyinforming decisions on including or removing them.
Super classes
pkgnet::AbstractPackageReporter ->pkgnet::AbstractGraphReporter ->DependencyReporter
Active bindings
report_markdown_path(character string) path to R Markdown template for this reporter. Read-only.
Methods
Public methods
Inherited methods
Methodnew()
Initialize an instance of the reporter.
Usage
DependencyReporter$new( dep_types = c("Imports", "Depends", "LinkingTo"), installed = TRUE)Arguments
dep_types(character vector) The sections within the
DESCRIPTIONfile to be counted as dependencies. By default, c("Imports", "Depends", "LinkingTo") is chosen.installed(logical) If
TRUE, consider only installed packages when building dependency network.
Returns
Self, invisibly.
Examples
\donttest{# Instantiate an objectreporter <- DependencyReporter$new()# Seed it with a packagereporter$set_package("ggplot2")}Methodclone()
The objects of this class are cloneable with this method.
Usage
DependencyReporter$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
Other Network Reporters:FunctionReporter,InheritanceReporter
Other Package Reporters:FunctionReporter,InheritanceReporter,SummaryReporter
Examples
## ------------------------------------------------## Method `DependencyReporter$new`## ------------------------------------------------# Instantiate an objectreporter <- DependencyReporter$new()# Seed it with a packagereporter$set_package("ggplot2")Directed Graph Network Model
Description
R6 class defining a directed graph model for representing anetwork, including methods to calculate various measures from graphtheory. Theigraph package is used as abackend for calculations.
This class isn't intended to be initialized directly; instead,network reporter objects will initialize it asitspkg_graph field. If you have a network reporter namedreporter, then you access this object's publicinterface throughpkg_graph—for example,
reporter$pkg_graph$node_measures('hubScore')Super class
pkgnet::AbstractGraph ->DirectedGraph
Active bindings
default_node_measurescharacter vector of default node measures. SeeNode Measures section inDirectedGraphMeasures for details about each measure. Read-only.
default_graph_measurescharacter vector of default graph measures. SeeGraph Measures section inDirectedGraphMeasures for details about each measure. Read-only.
Methods
Public methods
Inherited methods
Methodclone()
The objects of this class are cloneable with this method.
Usage
DirectedGraph$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
DirectedGraphMeasures
Measures for Directed Graph Class
Description
Descriptions for all available node and graph measures fornetworks modeled byDirectedGraph.
Node Measures
outDegreeoutdegree, the number of outward edges (tail ends).Calculated by
igraph::degree.[Wikipedia]inDegreeindegree, number of inward edges (head ends).Calculated by
igraph::degree.[Wikipedia]outClosenesscloseness centrality (out), a measure ofpath lengths to other nodes along edge directions.Calculated by
igraph::closeness.[Wikipedia]inClosenesscloseness centrality (in), a measure ofpath lengths to other nodes in reverse of edge directions.Calculated by
igraph::closeness.[Wikipedia]numRecursiveDepsnumber recursive dependencies, i.e., count of all nodes reachable by following edgesout from this node.Calculated by
igraph::neighborhood.size.[Wikipedia]numRecursiveRevDepsnumber of recursive reverse dependencies (dependents), i.e., count all nodes reachable by following edgesinto this node in reverse direction.Calculated by
igraph::neighborhood.size.[Wikipedia]betweennessbetweenness centrality, a measure ofthe number of shortest paths in graph passing through this nodeCalculated by
igraph::betweenness.[Wikipedia]pageRankGoogle PageRank.Calculated by
igraph::page_rank.[Wikipedia]hubScorehub score from Hyperlink-Induced TopicSearch (HITS) algorithm.Calculated by
igraph::hub_score.[Wikipedia]authorityScoreauthority score fromHyperlink-Induced Topic Search (HITS) algorithm.Calculated by
igraph::authority_score.[Wikipedia]
Graph Measures
graphOutDegreegraph freeman centralization foroutdegree. A measure of the most central node by outdegree in relation toall other nodes.Calculated by
igraph::centralize.[Wikipedia]graphInDegreegraph Freeman centralization forindegree. A measure of the most central node by indegree in relation toall other nodes.Calculated by
igraph::centralize.[Wikipedia]graphOutClosnessgraph Freeman centralization forout-closeness. A measure of the most central node by out-closeness in relation toall other nodes.Calculated by
igraph::centralize.[Wikipedia]graphInClosenessgraph Freeman centralization foroutdegree. A measure of the most central node by outdegree in relation toall other nodes.Calculated by
igraph::centralize.[Wikipedia]graphBetweennnessgraph Freeman centralization forbetweenness A measure of the most central node by betweenness in relation toall other nodes.Calculated by
igraph::centralize.[Wikipedia]
Function Interdependency Reporter
Description
This reporter looks at the network of interdependencies of itsdefined functions. Measures of centrality from graph theory can indicatewhich function is most important to a package. Combined with unit testcoverage information—also provided by this reporter— it can be usedas a powerful tool to prioritize test writing.
Details
R6 Method Support:
R6 classes are supported, with their methods treated as functions by thereporter.
R6 methods will be named like
<classname>$<methodtype>$<methodname>, e.g.,FunctionReporter$private_methods$extract_nodes.Note that the class name used will be thename of thegenerator object in the package's namespace.
The
classnameattribute of the class isnot used.In general, it is not required to be defined or the same as thegenerator object name. This attribute is used primarily forS3 dispatch.
Known Limitations:
Using non-standard evaluation to refer to things (e.g, dataframecolumn names) that have the same name as a function will trick
FunctionReporterinto thinking the function was called. Thiscan be avoided if you don't use reuse function names for otherpurposes.Functions stored as list items and not assigned to the packagenamespace will be invisible to
FunctionReporter.Calls to methods of instantiated R6 or reference objects willnot be recognized. We don't have a reliable way of identifyinginstantiated objects, or identifying their class.
Reference class methods are not yet supported. They will not beidentified as nodes by
FunctionReporter.
Super classes
pkgnet::AbstractPackageReporter ->pkgnet::AbstractGraphReporter ->FunctionReporter
Active bindings
report_markdown_path(character string) path to R Markdown template for this reporter. Read-only.
Methods
Public methods
Inherited methods
Methodcalculate_default_measures()
Calculates the default node and network measures for this reporter.
Usage
FunctionReporter$calculate_default_measures()
Returns
Self, invisibly.
Methodclone()
The objects of this class are cloneable with this method.
Usage
FunctionReporter$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
Other Network Reporters:DependencyReporter,InheritanceReporter
Other Package Reporters:DependencyReporter,InheritanceReporter,SummaryReporter
Class Inheritance Reporter
Description
This reporter takes a package and traces the class inheritancestructure. Currently the following object-oriented systems are supported:
S4 Classes
Reference Classes (sometimes informally called "R5")
R6 Classes
S3 classes are not supported, as their inheritance is defined on an ad hocbasis per object and not formally by class definitions.
Details
Note the following details about class naming:
Reference Classes : The name passed as
ClassinsetRefClassis used as the nodename by this reporter. This is the class name that is used whenspecifying inheritance. The generator object returned bysetRefClassdoes not have to beassigned and can have a different name.R6 Classes : The name of the generator object in the packagenamespace is used as the node name by this reporter. The generatorobject returned by
R6::R6Classis what isused when specifying inheritance. The name passed asclassnamepassed toR6::R6Classcan be a different nameor even NULL.
For more info about R's built-in object-oriented systems, check out therelevant chapter inHadleyWickham'sAdvanced R. For more info about R6, check out theirdocs website or the chapter inAdvanced R's second edition.
Super classes
pkgnet::AbstractPackageReporter ->pkgnet::AbstractGraphReporter ->InheritanceReporter
Active bindings
report_markdown_path(character string) path to R Markdown template for this reporter. Read-only.
Methods
Public methods
Inherited methods
Methodclone()
The objects of this class are cloneable with this method.
Usage
InheritanceReporter$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
Other Network Reporters:DependencyReporter,FunctionReporter
Other Package Reporters:DependencyReporter,FunctionReporter,SummaryReporter
R6 Class Representing an R Package Report
Description
pkgnet compiles one or more package reporters into a packagereport for a specified package.PackageReport is an R6 class thatholds all of those reporters and has a methodrender_report()to generate an HTML report file. You can access each individual reporterand modify it using its methods if you wish.
The functionCreatePackageReport() is a shortcut for bothgenerating aPackageReport object with instantiated reportersand creating the HTML report in one call.
Value
Self, invisibly.
Active bindings
pkg_name(character string) name of package. Read-only.
pkg_path(character string) path to source code of the package. Read-only.
report_path(character string) path and filename of output report.
SummaryReporterInstantiated pkgnet
SummaryReporterobjectDependencyReporterInstantiated pkgnet
DependencyReporterobjectFunctionReporterInstantiated pkgnet
FunctionReporterobjectInheritanceReporterInstantiated pkgnet
InheritanceReporterobject
Methods
Public methods
Methodnew()
Initialize an instance of a package report object.
Usage
PackageReport$new( pkg_name, pkg_path = NULL, report_path = tempfile(pattern = pkg_name, fileext = ".html"))
Arguments
pkg_name(character string) name of package
pkg_path(character string) optional directory path to source code of the package. It is used for calculating test coverage. It can be an absolute or relative path.
report_path(character string) The path and filename of the output report. Default report will be produced in the temporary directory.
Returns
Instantiated package report object.
Methodadd_reporter()
Add a reporter to the package report.
Usage
PackageReport$add_reporter(reporter)
Arguments
reporterInstantiated package reporter object
Returns
Self, invisibly
Methodrender_report()
Render html pkgnet package report.
Usage
PackageReport$render_report()
Methodclone()
The objects of this class are cloneable with this method.
Usage
PackageReport$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Package Summary Reporter
Description
This reporter provides a high-level overview of a package via its package DESCRIPTION file.
Super class
pkgnet::AbstractPackageReporter ->SummaryReporter
Active bindings
report_markdown_path(character string) path to R Markdown template for this reporter. Read-only.
Methods
Public methods
Inherited methods
Methodget_summary_view()
Returns an htmlwidget object that summarizes the analysis of the reporter. Used when creating apackage report.
Usage
SummaryReporter$get_summary_view()
Returns
Self, invisibly.
Methodclone()
The objects of this class are cloneable with this method.
Usage
SummaryReporter$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
Other Package Reporters:DependencyReporter,FunctionReporter,InheritanceReporter