Title: | Get Network Representation of an R Package |
---|---|
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. |
Authors: | Brian Burns [aut, cre], James Lamb [aut], Jay Qi [aut] |
Maintainer: | Brian Burns <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 0.5.0.9999 |
Built: | 2025-03-09 04:27:20 UTC |
Source: | https://github.com/uptake/pkgnet |
Create a standalone HTML report about a package and its networks.
CreatePackageReport( pkg_name, pkg_reporters = DefaultReporters(), pkg_path = NULL, report_path = tempfile(pattern = pkg_name, fileext = ".html") )
CreatePackageReport( pkg_name, pkg_reporters = DefaultReporters(), pkg_path = NULL, report_path = tempfile(pattern = pkg_name, fileext = ".html") )
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, coverage
will be calculated for each function. |
report_path |
(string) The path and filename of the output report. Default report will be produced in the temporary directory. |
an instantiated PackageReport
object
Create pkgnet package report as an R Markdown vignette. This
vignette can be rendered into a standard HTML vignette with the
knitr::rmarkdown
vignette engine
into 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 this
function, as well as
our example for pkgnet.
CreatePackageVignette( pkg = ".", pkg_reporters = list(DependencyReporter$new(), FunctionReporter$new()), vignette_path = file.path(pkg, "vignettes", "pkgnet-report.Rmd") )
CreatePackageVignette( pkg = ".", pkg_reporters = list(DependencyReporter$new(), FunctionReporter$new()), vignette_path = file.path(pkg, "vignettes", "pkgnet-report.Rmd") )
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 output vignette file at. Must be an .Rmd file. By default, this will be '<pkg>/vignettes/pkgnet-report.Rmd' relative to the input to pkg |
Instantiates a list of default reporters to feed into
CreatePackageReport
.
DefaultReporters()
DefaultReporters()
Default reporters are:
Note, InheritanceReporter
is not included in the default list.
If desired, append a new instance of InheritanceReporter
to the DefaultReporters
list.
ex:
c(DefaultReporters(), InheritanceReporter$new())
list of instantiated reporter objects
This reporter looks at the recursive network of its dependencies on other packages. This allows a developer to understand how individual dependencies might lead to a much larger set of dependencies, potentially informing decisions on including or removing them.
pkgnet::AbstractPackageReporter
-> pkgnet::AbstractGraphReporter
-> DependencyReporter
report_markdown_path
(character string) path to R Markdown template for this reporter. Read-only.
new()
Initialize an instance of the reporter.
DependencyReporter$new( dep_types = c("Imports", "Depends", "LinkingTo"), installed = TRUE )
dep_types
(character vector) The sections within the DESCRIPTION
file 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.
Self, invisibly.
\donttest{ # Instantiate an object reporter <- DependencyReporter$new() # Seed it with a package reporter$set_package("ggplot2") }
clone()
The objects of this class are cloneable with this method.
DependencyReporter$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other Network Reporters:
FunctionReporter
,
InheritanceReporter
Other Package Reporters:
FunctionReporter
,
InheritanceReporter
,
SummaryReporter
## ------------------------------------------------ ## Method `DependencyReporter$new` ## ------------------------------------------------ # Instantiate an object reporter <- DependencyReporter$new() # Seed it with a package reporter$set_package("ggplot2")
## ------------------------------------------------ ## Method `DependencyReporter$new` ## ------------------------------------------------ # Instantiate an object reporter <- DependencyReporter$new() # Seed it with a package reporter$set_package("ggplot2")
R6 class defining a directed graph model for representing a network, including methods to calculate various measures from graph theory. The igraph package is used as a backend for calculations.
This class isn't intended to be initialized directly; instead,
network reporter objects will initialize it as
its pkg_graph
field. If you have a network reporter named
reporter
, then you access this object's public
interface through pkg_graph
—for example,
reporter$pkg_graph$node_measures('hubScore')
pkgnet::AbstractGraph
-> DirectedGraph
default_node_measures
character vector of default node measures. See Node Measures section in DirectedGraphMeasures for details about each measure. Read-only.
default_graph_measures
character vector of default graph measures. See Graph Measures section in DirectedGraphMeasures for details about each measure. Read-only.
clone()
The objects of this class are cloneable with this method.
DirectedGraph$clone(deep = FALSE)
deep
Whether to make a deep clone.
DirectedGraphMeasures
This reporter looks at the network of interdependencies of its defined functions. Measures of centrality from graph theory can indicate which function is most important to a package. Combined with unit test coverage information—also provided by this reporter— it can be used as a powerful tool to prioritize test writing.
R6 classes are supported, with their methods treated as functions by the reporter.
R6 methods will be named like
<classname>$<methodtype>$<methodname>
, e.g.,
FunctionReporter$private_methods$extract_nodes
.
Note that the class name used will be the name of the generator object in the package's namespace.
The classname
attribute of the class is not used.
In general, it is not required to be defined or the same as the
generator object name. This attribute is used primarily for
S3 dispatch.
Using non-standard evaluation to refer to things (e.g, dataframe
column names) that have the same name as a function will trick
FunctionReporter
into thinking the function was called. This
can be avoided if you don't use reuse function names for other
purposes.
Functions stored as list items and not assigned to the package
namespace will be invisible to FunctionReporter
.
Calls to methods of instantiated R6 or reference objects will not be recognized. We don't have a reliable way of identifying instantiated objects, or identifying their class.
Reference class methods are not yet supported. They will not be
identified as nodes by FunctionReporter
.
pkgnet::AbstractPackageReporter
-> pkgnet::AbstractGraphReporter
-> FunctionReporter
report_markdown_path
(character string) path to R Markdown template for this reporter. Read-only.
calculate_default_measures()
Calculates the default node and network measures for this reporter.
FunctionReporter$calculate_default_measures()
Self, invisibly.
clone()
The objects of this class are cloneable with this method.
FunctionReporter$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other Network Reporters:
DependencyReporter
,
InheritanceReporter
Other Package Reporters:
DependencyReporter
,
InheritanceReporter
,
SummaryReporter
This reporter takes a package and traces the class inheritance structure. 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 hoc basis per object and not formally by class definitions.
Note the following details about class naming:
Reference Classes : The name passed as Class
in
setRefClass
is used as the node
name by this reporter. This is the class name that is used when
specifying inheritance. The generator object returned by
setRefClass
does not have to be
assigned and can have a different name.
R6 Classes : The name of the generator object in the package
namespace is used as the node name by this reporter. The generator
object returned by R6::R6Class
is what is
used when specifying inheritance. The name passed as classname
passed to R6::R6Class
can be a different name
or even NULL.
For more info about R's built-in object-oriented systems, check out the relevant chapter in Hadley Wickham's Advanced R. For more info about R6, check out their docs website or the chapter in Advanced R's second edition.
pkgnet::AbstractPackageReporter
-> pkgnet::AbstractGraphReporter
-> InheritanceReporter
report_markdown_path
(character string) path to R Markdown template for this reporter. Read-only.
clone()
The objects of this class are cloneable with this method.
InheritanceReporter$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other Network Reporters:
DependencyReporter
,
FunctionReporter
Other Package Reporters:
DependencyReporter
,
FunctionReporter
,
SummaryReporter
pkgnet compiles one or more package reporters into a package
report for a specified package. PackageReport
is an R6 class that
holds all of those reporters and has a method render_report()
to generate an HTML report file. You can access each individual reporter
and modify it using its methods if you wish.
The function CreatePackageReport()
is a shortcut for both
generating a PackageReport
object with instantiated reporters
and creating the HTML report in one call.
Self, invisibly.
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.
SummaryReporter
Instantiated pkgnet SummaryReporter
object
DependencyReporter
Instantiated pkgnet DependencyReporter
object
FunctionReporter
Instantiated pkgnet FunctionReporter
object
InheritanceReporter
Instantiated pkgnet InheritanceReporter
object
new()
Initialize an instance of a package report object.
PackageReport$new( pkg_name, pkg_path = NULL, report_path = tempfile(pattern = pkg_name, fileext = ".html") )
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.
Instantiated package report object.
add_reporter()
Add a reporter to the package report.
PackageReport$add_reporter(reporter)
reporter
Instantiated package reporter object
Self, invisibly
render_report()
Render html pkgnet package report.
PackageReport$render_report()
clone()
The objects of this class are cloneable with this method.
PackageReport$clone(deep = FALSE)
deep
Whether to make a deep clone.
This reporter provides a high-level overview of a package via its package DESCRIPTION file.
pkgnet::AbstractPackageReporter
-> SummaryReporter
report_markdown_path
(character string) path to R Markdown template for this reporter. Read-only.
get_summary_view()
Returns an htmlwidget object that summarizes the analysis of the reporter. Used when creating a package report.
SummaryReporter$get_summary_view()
Self, invisibly.
clone()
The objects of this class are cloneable with this method.
SummaryReporter$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other Package Reporters:
DependencyReporter
,
FunctionReporter
,
InheritanceReporter