Title: | Metrics of R Packages |
---|---|
Description: | Static code analyses for R packages using the external code-tagging libraries 'ctags' and 'gtags'. Static analyses enable packages to be analysed very quickly, generally a couple of seconds at most. The package also provides access to a database generating by applying the main function to the full 'CRAN' archive, enabling the statistical properties of any package to be compared with all other 'CRAN' packages. |
Authors: | Mark Padgham [aut, cre] |
Maintainer: | Mark Padgham <[email protected]> |
License: | GPL-3 |
Version: | 0.2.0.048 |
Built: | 2024-12-05 06:29:18 UTC |
Source: | https://github.com/ropensci-review-tools/pkgstats |
'ctags' is installed with this package on both Windows and macOS systems; this is an additional function to install from source on Unix systems.
ctags_install(bin_dir = NULL, sudo = TRUE)
ctags_install(bin_dir = NULL, sudo = TRUE)
bin_dir |
Prefix to pass to the |
sudo |
Set to |
Nothing; the function will fail if installation fails, otherwise returns nothing.
Other tags:
ctags_test()
,
tags_data()
## Not run: ctags_install (bin_dir = "/usr/local") # default ## End(Not run)
## Not run: ctags_install (bin_dir = "/usr/local") # default ## End(Not run)
This uses the example from https://github.com/universal-ctags/ctags/blob/master/man/ctags-lang-r.7.rst.in and also checks the GNU global installation.
ctags_test(quiet = TRUE)
ctags_test(quiet = TRUE)
quiet |
If |
'TRUE' or 'FALSE' respectively indicating whether or not 'ctags' is correctly installed.
Other tags:
ctags_install()
,
tags_data()
## Not run: ctags_test () ## End(Not run)
## Not run: ctags_test () ## End(Not run)
Statistics from DESCRIPTION files
desc_stats(path)
desc_stats(path)
path |
Directory to source code of package being analysed |
A data.frame
with one row and 16 columns extracting various
information from the 'DESCRIPTION' file, include websites, tallies of
different kinds of authors and contributors, and package dependencies.
Other stats:
loc_stats()
,
pkgstats()
,
pkgstats_summary()
,
rd_stats()
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") # have to extract tarball to call function on source code: path <- extract_tarball (f) desc_stats (path)
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") # have to extract tarball to call function on source code: path <- extract_tarball (f) desc_stats (path)
Download latest version of 'pkgstats' data
dl_pkgstats_data(current = TRUE, path = tempdir(), quiet = FALSE)
dl_pkgstats_data(current = TRUE, path = tempdir(), quiet = FALSE)
current |
If 'FALSE', download data for all CRAN packages ever released, otherwise (default) download data only for current CRAN packages. |
path |
Local path to download file. |
quiet |
If |
(Invisibly) A data.frame
of pkgstats
results, one row for each
package.
Other archive:
pkgstats_cran_current_from_full()
,
pkgstats_fns_from_archive()
,
pkgstats_fns_update()
,
pkgstats_from_archive()
,
pkgstats_update()
Extract tarball of a package into temp directory and return path to extracted package
extract_tarball(tarball)
extract_tarball(tarball)
tarball |
Full path to local tarball of an R package. |
Path to extracted version of package (in tempdir()
).
Other misc:
pkgstats_fn_names()
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") path <- extract_tarball (f)
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") path <- extract_tarball (f)
Internal calculation of Lines-of-Code Statistics
loc_stats(path)
loc_stats(path)
path |
Directory to source code of package being analysed |
A list of statistics for each of three directories, 'R', 'src', and 'inst/include', each one having 5 statistics of total numbers of lines, numbers of empty lines, total numbers of white spaces, total numbers of characters, and indentation used in files in that directory.
NA values are returned for directories which do not exist.
Other stats:
desc_stats()
,
pkgstats()
,
pkgstats_summary()
,
rd_stats()
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") # have to extract tarball to call function on source code: path <- extract_tarball (f) loc_stats (path)
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") # have to extract tarball to call function on source code: path <- extract_tarball (f) loc_stats (path)
Analyse statistics of one R package
pkgstats(path = ".")
pkgstats(path = ".")
path |
Either a path to a local source repository, or a local '.tar.gz' file, containing code for an R package. |
List of statistics and data on function call networks (or object relationships in other languages). Includes the following components:
loc: Summary of Lines-of-Code in all package directories
vignettes: Numbers of vignettes and "demo" files
data_stats: Statistics of numbers and sizes of package data files
desc: Summary of contents of 'DESCRIPTION' file
translations: List of translations into other (human) languages (where provides)
objects: A data.frame
of all functions in R, and all other
objects (functions, classes, structures, global variables, and more) in all
other languages
network: A data.frame
of object references within and between all
languages; in R these are function calls, but may be more abstract in other
languages.
external_calls: A data.frame
of all calls make to all functions
from all other R packages, including base and recommended as well as
contributed packages.
Other stats:
desc_stats()
,
loc_stats()
,
pkgstats_summary()
,
rd_stats()
# 'path' can be path to a package tarball: f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") ## Not run: s <- pkgstats (f) ## End(Not run) # or to a source directory: path <- extract_tarball (f) ## Not run: s <- pkgstats (path) ## End(Not run)
# 'path' can be path to a package tarball: f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") ## Not run: s <- pkgstats (f) ## End(Not run) # or to a source directory: path <- extract_tarball (f) ## Not run: s <- pkgstats (path) ## End(Not run)
data.frame
of full CRAN archive data to current packages only.Reduce data.frame
of full CRAN archive data to current packages only.
pkgstats_cran_current_from_full(prev_results, results_file = NULL)
pkgstats_cran_current_from_full(prev_results, results_file = NULL)
prev_results |
Result of previous call to this function, if available.
Submitting previous results will ensure that only newer packages not present
in previous result will be analysed, with new results simply appended to
previous results. This parameter can also specify a file to be read with
|
results_file |
Can be used to specify the name or full path of a |
Other archive:
dl_pkgstats_data()
,
pkgstats_fns_from_archive()
,
pkgstats_fns_update()
,
pkgstats_from_archive()
,
pkgstats_update()
Extract names of all functions for one R package
pkgstats_fn_names(path)
pkgstats_fn_names(path)
path |
Either a path to a local source repository, or a local '.tar.gz' file, containing code for an R package. |
A data.frame
with three columns:
package: Name of package
version: Package version
fn_name: Name of function
Other misc:
extract_tarball()
# 'path' can be path to a package tarball: f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") path <- extract_tarball (f) s <- pkgstats_fn_names (path)
# 'path' can be path to a package tarball: f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") path <- extract_tarball (f) s <- pkgstats_fn_names (path)
Trawl a local CRAN archive to extract function names only from all packages
pkgstats_fns_from_archive( path, archive = FALSE, prev_results = NULL, results_file = NULL, chunk_size = 1000L, num_cores = 1L, results_path = fs::path_temp() )
pkgstats_fns_from_archive( path, archive = FALSE, prev_results = NULL, results_file = NULL, chunk_size = 1000L, num_cores = 1L, results_path = fs::path_temp() )
path |
Path to local archive of R packages, either as source directories, or '.tar.gz' files such as in a CRAN mirror. |
archive |
If |
prev_results |
Result of previous call to this function, if available.
Submitting previous results will ensure that only newer packages not present
in previous result will be analysed, with new results simply appended to
previous results. This parameter can also specify a file to be read with
|
results_file |
Can be used to specify the name or full path of a |
chunk_size |
Divide large archive trawl into chunks of this size, and
save intermediate results to local files. These intermediate files can be
combined to generate a single |
num_cores |
Number of machine cores to use in parallel, defaulting to single-core processing. |
results_path |
Path to save intermediate files generated by the
|
A data.frame
object with one row for each function in each package
and the following columns:
Package name
Package version
Function name
Other archive:
dl_pkgstats_data()
,
pkgstats_cran_current_from_full()
,
pkgstats_fns_update()
,
pkgstats_from_archive()
,
pkgstats_update()
Update function names data from previous data and newly updated CRAN packages only.
pkgstats_fns_update( prev_results = NULL, results_file = NULL, chunk_size = 1000L, num_cores = 1L, results_path = tempdir() )
pkgstats_fns_update( prev_results = NULL, results_file = NULL, chunk_size = 1000L, num_cores = 1L, results_path = tempdir() )
prev_results |
Result of previous call to this function, if available.
Submitting previous results will ensure that only newer packages not present
in previous result will be analysed, with new results simply appended to
previous results. This parameter can also specify a file to be read with
|
results_file |
Can be used to specify the name or full path of a |
chunk_size |
Divide large archive trawl into chunks of this size, and
save intermediate results to local files. These intermediate files can be
combined to generate a single |
num_cores |
Number of machine cores to use in parallel, defaulting to single-core processing. |
results_path |
Path to save intermediate files generated by the
|
A data.frame
object with one row for each function in each package
and the following columns:
Package name
Package version
Function name
Other archive:
dl_pkgstats_data()
,
pkgstats_cran_current_from_full()
,
pkgstats_fns_from_archive()
,
pkgstats_from_archive()
,
pkgstats_update()
Trawl a local CRAN archive and extract statistics from all packages
pkgstats_from_archive( path, archive = TRUE, prev_results = NULL, results_file = NULL, chunk_size = 1000L, num_cores = 1L, save_full = FALSE, save_ex_calls = FALSE, results_path = fs::path_temp() )
pkgstats_from_archive( path, archive = TRUE, prev_results = NULL, results_file = NULL, chunk_size = 1000L, num_cores = 1L, save_full = FALSE, save_ex_calls = FALSE, results_path = fs::path_temp() )
path |
Path to local archive of R packages, either as source directories, or '.tar.gz' files such as in a CRAN mirror. |
archive |
If |
prev_results |
Result of previous call to this function, if available.
Submitting previous results will ensure that only newer packages not present
in previous result will be analysed, with new results simply appended to
previous results. This parameter can also specify a file to be read with
|
results_file |
Can be used to specify the name or full path of a |
chunk_size |
Divide large archive trawl into chunks of this size, and
save intermediate results to local files. These intermediate files can be
combined to generate a single |
num_cores |
Number of machine cores to use in parallel, defaulting to single-core processing. |
save_full |
If |
save_ex_calls |
If |
results_path |
Path to save intermediate files generated by the
|
A data.frame
object with one row for each package containing
summary statistics generated from the pkgstats_summary function.
Other archive:
dl_pkgstats_data()
,
pkgstats_cran_current_from_full()
,
pkgstats_fns_from_archive()
,
pkgstats_fns_update()
,
pkgstats_update()
# Create fake archive directory with single tarball: f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") tarball <- basename (f) archive_path <- file.path (tempdir (), "archive") if (!dir.exists (archive_path)) { dir.create (archive_path) } path <- file.path (archive_path, tarball) file.copy (f, path) tarball_path <- file.path (archive_path, "tarballs") dir.create (tarball_path, recursive = TRUE) file.copy (path, file.path (tarball_path, tarball)) ## Not run: out <- pkgstats_from_archive (tarball_path) ## End(Not run)
# Create fake archive directory with single tarball: f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") tarball <- basename (f) archive_path <- file.path (tempdir (), "archive") if (!dir.exists (archive_path)) { dir.create (archive_path) } path <- file.path (archive_path, tarball) file.copy (f, path) tarball_path <- file.path (archive_path, "tarballs") dir.create (tarball_path, recursive = TRUE) file.copy (path, file.path (tarball_path, tarball)) ## Not run: out <- pkgstats_from_archive (tarball_path) ## End(Not run)
pkgstats
to summary statistics onlyCondense the output of pkgstats
to summary statistics only
pkgstats_summary(s = NULL)
pkgstats_summary(s = NULL)
s |
Output of pkgstats, containing full statistical data on one
package. Default of |
Summarised version of s
, as a single row of a standardised
data.frame
object
Variable names in the summary object use the following abbreviations:
"loc" = Lines-of-Code
"fn" = Function
"n_fns" = Number of functions
"npars" = Number of parameters
"doclines" = Number of documentation lines
"nedges" = Number of edges in function call network, as a count of
unique edges, which may be less than the size of the network
object returned by pkgstats, because that may include multiple calls
between identical function pairs.
"n_clusters" = Number of connected clusters within the function call network.
"centrality" used as a prefix for several statistics, along with "dir" or "undir" for centrality calculated on networks respectively constructed with directed or undirected edges; "mn" or "md" for respective measures of mean or median centrality, and "no0" for measures excluding edges with zero centrality.
Other stats:
desc_stats()
,
loc_stats()
,
pkgstats()
,
rd_stats()
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") ## Not run: p <- pkgstats (f) s <- pkgstats_summary (p) ## End(Not run)
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") ## Not run: p <- pkgstats (f) s <- pkgstats_summary (p) ## End(Not run)
This function is intended for internal rOpenSci use only. Usage by any
unauthorized users will error and have no effect unless run with upload = FALSE
, in which case updated data will be created in the sub-directory
"pkgstats-results" of R's current temporary directory.
pkgstats_update(upload = TRUE)
pkgstats_update(upload = TRUE)
upload |
If |
Local path to directory containing updated results.
Other archive:
dl_pkgstats_data()
,
pkgstats_cran_current_from_full()
,
pkgstats_fns_from_archive()
,
pkgstats_fns_update()
,
pkgstats_from_archive()
Plot interactive visNetwork visualisation of object-relationship network of package.
plot_network(s, plot = TRUE, vis_save = NULL)
plot_network(s, plot = TRUE, vis_save = NULL)
s |
Package statistics obtained from pkgstats function. |
plot |
If |
vis_save |
Name of local file in which to save |
(Invisibly) A visNetwork representation of the package network.
Edge thicknesses are scaled to centrality within the package function call network. Node sizes are scaled to numbers of times each function is called from all other functions within a package.
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") ## Not run: p <- pkgstats (f) plot_network (p) ## End(Not run)
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") ## Not run: p <- pkgstats (f) plot_network (p) ## End(Not run)
Stats from '.Rd' files
rd_stats(path)
rd_stats(path)
path |
Directory to source code of package being analysed |
A data.frame
of function names and numbers of parameters and lines
of documentation for each, along with mean and median numbers of characters
used to document each parameter.
Other stats:
desc_stats()
,
loc_stats()
,
pkgstats()
,
pkgstats_summary()
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") # have to extract tarball to call function on source code: path <- extract_tarball (f) rd_stats (path)
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") # have to extract tarball to call function on source code: path <- extract_tarball (f) rd_stats (path)
use ctags and gtags to parse call data
tags_data(path, has_tabs = NULL, pkg_name = NULL)
tags_data(path, has_tabs = NULL, pkg_name = NULL)
path |
Path to local repository |
has_tabs |
A logical flag indicating whether or not the code contains
any tab characters. This can be determined from loc_stats, which has a
|
pkg_name |
Only used for external_call_network, to label package-internal calls. |
A list of three items:
"network" A data.frame
of relationships between objects, generally as
calls between functions in R, but other kinds of relationships in other
source languages. This is effectively an edge-based network representation,
and the data frame also include network metrics for each edge, calculated
through representing the network in both directed (suffix "_dir") and
undirected (suffix "_undir") forms.
"objects" A data.frame
of statistics on each object (generally
functions in R, and other kinds of objects in other source languages),
including the kind of object, the language, numbers of lines-of-code,
parameters, and lines of documentation, and a binary flag indicating whether
or not R functions accept "three-dots" parameters (...
).
"external_calls" A data.frame
of every call from within every R
function to any external R package, including base and recommended packages.
The location of each calls is recorded, along with the external function and
package being called.
Other tags:
ctags_install()
,
ctags_test()
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") # have to extract tarball to call function on source code: path <- extract_tarball (f) ## Not run: tags <- tags_data (path) ## End(Not run)
f <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") # have to extract tarball to call function on source code: path <- extract_tarball (f) ## Not run: tags <- tags_data (path) ## End(Not run)