Movatterモバイル変換


[0]ホーム

URL:


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:

DependencyReporter

analyze the recursivenetwork of packages that the subject package depends on.

FunctionReporter

analyze the network ofinterdependencies of the functions defined in the subject package

InheritanceReporter

analyze the classinheritance trees for subject packages that use object-orientedprogramming.

SummaryReporter

get 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:

See Also

Useful links:


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

nodes

node data.table, read-only.

edges

edge data.table, read-only.

igraph

igraph object, read-only.

available_node_measures

character vector of all supported node measures. SeeNode Measures section inDirectedGraphMeasures for details about each measure.

available_graph_measures

character vector of all supported graph measures. SeeGraph Measures section inDirectedGraphMeasures for details about each measure. Read-only.

default_node_measures

character vector of default node measures. SeeNode Measures section inDirectedGraphMeasures for details about each measure.

default_graph_measures

character 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
nodes

a data.table containing nodes

edges

a 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
measures

character 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
measures

character 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
deep

Whether 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

nodes

A data.table, containing information aboutthe nodes of the network the reporter is analyzing. Thenode column acts the identifier. Read-only.

edges

A data.table, containing information aboutthe edge connections of the network the reporter is analyzing. Eachrow is one edge, and the columnsSOURCE andTARGETspecify the node identifiers. Read-only.

network_measures

A list, containing any measures of the network calculated by the reporter. Read-only.

pkg_graph

a graph model object. SeeDirectedGraphfor additional documentation. Read-only.

graph_viz

a graph visualization object. AvisNetwork::visNetwork object.Read-only.

layout_type

a character string, the current layout type for the graph visualization. Can be assigned a new valid layout type value. Use usegrep("^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
deep

Whether 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
deep

Whether 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.pkg_path can be anabsolute or relative path.

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 theDESCRIPTION file to be counted as dependencies. By default, c("Imports", "Depends", "LinkingTo") is chosen.

installed

(logical) IfTRUE, 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
deep

Whether 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_measures

character vector of default node measures. SeeNode Measures section inDirectedGraphMeasures for details about each measure. Read-only.

default_graph_measures

character 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
deep

Whether 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

outDegree

outdegree, the number of outward edges (tail ends).Calculated byigraph::degree.[Wikipedia]

inDegree

indegree, number of inward edges (head ends).Calculated byigraph::degree.[Wikipedia]

outCloseness

closeness centrality (out), a measure ofpath lengths to other nodes along edge directions.Calculated byigraph::closeness.[Wikipedia]

inCloseness

closeness centrality (in), a measure ofpath lengths to other nodes in reverse of edge directions.Calculated byigraph::closeness.[Wikipedia]

numRecursiveDeps

number recursive dependencies, i.e., count of all nodes reachable by following edgesout from this node.Calculated byigraph::neighborhood.size.[Wikipedia]

numRecursiveRevDeps

number of recursive reverse dependencies (dependents), i.e., count all nodes reachable by following edgesinto this node in reverse direction.Calculated byigraph::neighborhood.size.[Wikipedia]

betweenness

betweenness centrality, a measure ofthe number of shortest paths in graph passing through this nodeCalculated byigraph::betweenness.[Wikipedia]

pageRank

Google PageRank.Calculated byigraph::page_rank.[Wikipedia]

hubScore

hub score from Hyperlink-Induced TopicSearch (HITS) algorithm.Calculated byigraph::hub_score.[Wikipedia]

authorityScore

authority score fromHyperlink-Induced Topic Search (HITS) algorithm.Calculated byigraph::authority_score.[Wikipedia]

Graph Measures

graphOutDegree

graph freeman centralization foroutdegree. A measure of the most central node by outdegree in relation toall other nodes.Calculated byigraph::centralize.[Wikipedia]

graphInDegree

graph Freeman centralization forindegree. A measure of the most central node by indegree in relation toall other nodes.Calculated byigraph::centralize.[Wikipedia]

graphOutClosness

graph Freeman centralization forout-closeness. A measure of the most central node by out-closeness in relation toall other nodes.Calculated byigraph::centralize.[Wikipedia]

graphInCloseness

graph Freeman centralization foroutdegree. A measure of the most central node by outdegree in relation toall other nodes.Calculated byigraph::centralize.[Wikipedia]

graphBetweennness

graph Freeman centralization forbetweenness A measure of the most central node by betweenness in relation toall other nodes.Calculated byigraph::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.

Known Limitations:

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
deep

Whether 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:

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:

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
deep

Whether 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.

SummaryReporter

Instantiated pkgnetSummaryReporter object

DependencyReporter

Instantiated pkgnetDependencyReporter object

FunctionReporter

Instantiated pkgnetFunctionReporter object

InheritanceReporter

Instantiated pkgnetInheritanceReporter object

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
reporter

Instantiated 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
deep

Whether 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
deep

Whether to make a deep clone.

See Also

Other Package Reporters:DependencyReporter,FunctionReporter,InheritanceReporter


[8]ページ先頭

©2009-2025 Movatter.jp