Title: | Assessing Package Risk Metrics |
Version: | 2.0.0 |
Description: | Provides a structured approach to assess the quality and trustworthiness of R packages (documentation, testing, popularity, dependencies), supporting informed decisions in production or research by highlighting strengths and potential risks in adoption or development. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
URL: | https://sanofi-public.github.io/risk.assessr/ |
BugReports: | https://github.com/Sanofi-Public/risk.assessr/issues |
Depends: | R (≥ 4.1.0) |
Imports: | remotes, callr, checkmate, covr, desc, devtools, dplyr, fs, methods, purrr, rcmdcheck, rlang, xml2, stringr, tidyr, utils, curl, gh, jsonlite |
Suggests: | forcats, glue, here, htmltools, kableExtra, knitr, magrittr, openxlsx, readr, roxygen2, testthat (≥ 3.0.0), tidyselect, tools, rmarkdown, withr, mockery |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Config/testthat/edition: | 3 |
Config/build/clean-inst-doc: | false |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2025-07-07 14:25:15 UTC; u1004798 |
Author: | Edward Gillian |
Maintainer: | Edward Gillian <edward.gillian-ext@sanofi.com> |
Repository: | CRAN |
Date/Publication: | 2025-07-10 15:20:02 UTC |
risk.assessr: Assessing Package Risk Metrics
Description
Provides a structured approach to assess the quality and trustworthiness of R packages (documentation, testing, popularity, dependencies), supporting informed decisions in production or research by highlighting strengths and potential risks in adoption or development.
Author(s)
Maintainer: Edward Gillian edward.gillian-ext@sanofi.com (ORCID)
Authors:
Hugo Bottois hugo.bottois@sanofi.com (ORCID)
Paulin Charliquart paulin.charliquart@sanofi.com
Andre Couturier andre.couturier@sanofi.com
Other contributors:
Sanofi [copyright holder, funder]
See Also
Useful links:
Report bugs at https://github.com/Sanofi-Public/risk.assessr/issues
Set the default weight of each metric to 1.
Description
Set the default weight of each metric to 1.
Usage
add_default_risk_weights(data)
Arguments
data |
risk metric data |
Assess dependencies for sigmoid point
Description
This function calculates average number of dependencies to determine the dependency sigmoid point
Usage
assess_dep_for_sigmoid(riskdata_results)
Arguments
riskdata_results |
- path to riskdata_results |
Value
nested list with dependencies, Import count mean, and all dependency count and mean
assess_description_file_elements
Description
assess_description_file_elements
Usage
assess_description_file_elements(pkg_name, pkg_source_path)
Arguments
pkg_name |
- name of the package |
pkg_source_path |
- pkg_source_path - source path for install local |
Value
- list - list with scores for description file elements
Assess Rd files for example or examples
Description
Assess Rd files for example or examples
Usage
assess_examples(pkg_name, pkg_source_path)
Arguments
pkg_name |
- name of the package |
pkg_source_path |
- source path for install local |
Value
has_examples - variable with score
assess_export_help
Description
assess_export_help
Usage
assess_export_help(pkg_name, pkg_source_path)
Arguments
pkg_name |
- name of the package |
pkg_source_path |
- pkg_source_path - source path for install local |
Value
- export_help - variable with score
Assess exported functions to namespace
Description
Assess exported functions to namespace
Usage
assess_exports(data)
Arguments
data |
pkg source path |
Assess Rd files for news
Description
Assess Rd files for news
Usage
assess_news(pkg_name, pkg_source_path)
Arguments
pkg_name |
- name of the package |
pkg_source_path |
- source path for install local |
Value
has_news - variable with score
Assess Rd files for news
Description
Assess Rd files for news
Usage
assess_news_current(pkg_name, pkg_ver, pkg_source_path)
Arguments
pkg_name |
- name of the package |
pkg_ver |
- package version |
pkg_source_path |
- source path for install local |
Value
news_current - variable with score
Assess package
Description
assess package for risk metrics
Usage
assess_pkg(pkg_source_path, rcmdcheck_args, covr_timeout = Inf)
Arguments
pkg_source_path |
- source path for install local |
rcmdcheck_args |
- arguments for R Cmd check - these come from setup_rcmdcheck_args |
covr_timeout |
- setting for covr time out |
Value
list containing results - list containing metrics, covr, tm - trace matrix, and R CMD check
Examples
## Not run:
# set CRAN repo to enable running of reverse dependencies
r = getOption("repos")
r["CRAN"] = "http://cran.us.r-project.org"
old <- options(repos = r)
pkg_source_path <- system.file("test-data", "here-1.0.1.tar.gz",
package = "risk.assessr")
pkg_name <- sub("\\.tar\\.gz$", "", basename(pkg_source_path))
modified_tar_file <- modify_description_file(pkg_source_path)
# Set up the package using the temporary file
install_list <- set_up_pkg(modified_tar_file)
# Extract information from the installation list
build_vignettes <- install_list$build_vignettes
package_installed <- install_list$package_installed
pkg_source_path <- install_list$pkg_source_path
rcmdcheck_args <- install_list$rcmdcheck_args
# check if the package needs to be installed locally
package_installed <- install_package_local(pkg_source_path)
# Check if the package was installed successfully
if (package_installed == TRUE) {
# Assess the package
assess_package <- assess_pkg(pkg_source_path, rcmdcheck_args)
# Output the assessment result
} else {
message("Package installation failed.")
}
options(old)
## End(Not run)
Assess an R Package riskmetric with package name and version
Description
This function use 'risk.assessr::assess_pkg' assessment function with only the package name and version
Usage
assess_pkg_r_package(package_name, version = NA, repos = NULL)
Arguments
package_name |
A character string specifying the name of the package to assess. |
version |
A character string specifying the version of the package to assess. Default is 'NA', which assesses the latest version. |
repos |
A character string specifying the repo directly. Default is NULL, which uses the CRAN mirrors |
Details
This function follows these steps:
Downloads the specified R package
Installs the downloaded package in a temporary location.
Runs the 'risk.assessr::assess_pkg' function to assess the package for risks and issues.
Returns the results of the assessment.
Value
The function returns a list of assessment results generated by the 'risk.assessr::assess_pkg' function. If the package cannot be downloaded or installed, an error message is returned.
Examples
## Not run:
# Example usage of assess_pkg_r_package
results <- assess_pkg_r_package("here", version = "1.0.1")
print(results)
## End(Not run)
assess codebase size
Description
Scores packages based on its codebase size, as determined by number of lines of code.
Usage
assess_size_codebase(pkg_source_path)
Arguments
pkg_source_path |
- source path for install local |
Value
- size_codebase - numeric value between 0
(for small codebase) and 1
(for large codebase)
Assess vignettes
Description
Assess vignettes
Usage
assess_vignettes(pkg_name, pkg_source_path)
Arguments
pkg_name |
- name of the package |
pkg_source_path |
- source path for install local |
Value
- has_vignettes - variable with score
Calculate dependency score
Description
Calculate dependency score
Usage
calc_dependencies(pkg_source_path)
Arguments
pkg_source_path |
package source path |
Calculate overall package risk scores
Description
Calculate overall package risk scores
Usage
calc_overall_risk_score(data, default_weights = FALSE)
Arguments
data |
risk metric data |
default_weights |
logical T/F for weights choice |
Value
pkg_score
Examples
data <- list(
pkg_name = "synapser",
pkg_version = "0.2.1",
pkg_source_path = "/tmp/RtmpNpDlUz/temp_file_1fe56774aacc/synapser",
has_bug_reports_url = 1,
has_examples = 1,
has_maintainer = 1,
size_codebase = 0.06702413,
has_news = 0,
has_source_control = 0,
has_vignettes = 1,
has_website = 1,
news_current = 0,
export_help = 1,
export_calc = 0.586281,
check = .7,
covr = .1084,
dep_score = .9706878,
revdep_score = .1260338
)
overall_risk_score <-
calc_overall_risk_score(data,
default_weights = TRUE)
Calculate reverse dependency score
Description
Calculate reverse dependency score
Usage
calc_reverse_dependencies(pkg_source_path)
Arguments
pkg_source_path |
package source path |
Calculate package risk profile
Description
Calculate package risk profile
Usage
calc_risk_profile(risk_data)
Arguments
risk_data |
overall risk score |
Value
risk_profile
Examples
## Not run:
# Toy dataset
toy_data <- data.frame(score = c(0.1, 0.2, 0.3, 0.4, 0.8, 1.2))
calc_risk_profile(toy_data)
## End(Not run)
Check and Fetch CRAN Package
Description
This function checks if a package exists on CRAN and retrieves the corresponding package URL and version details. If a specific version is not provided, the latest version is used.
Usage
check_and_fetch_cran_package(package_name, package_version = NULL)
Arguments
package_name |
A character string specifying the name of the package to check and fetch. |
package_version |
An optional character string specifying the version of the package to fetch. Defaults to 'NULL'. |
Value
A list containing: - 'package_url': URL to download the package tarball. - 'last_version': Latest version available - 'version': The requested version of the package (or 'NULL' if not specified). - 'all_versions': A character vector of all available package versions - 'error': If the package or version is not found, an error message is included.
Examples
## Not run:
# Check and fetch a specific version of "ggplot2"
result <- check_and_fetch_cran_package("ggplot2", package_version = "3.3.5")
print(result)
## End(Not run)
Check if a Package Exists on CRAN
Description
This function checks if a given package is available on CRAN.
Usage
check_cran_package(package_name)
Arguments
package_name |
A character string specifying the name of the package to check. |
Value
A logical value: 'TRUE' if the package exists on CRAN, 'FALSE' otherwise.
Examples
## Not run:
# Check if the package "ggplot2" exists on CRAN
check_cran_package("ggplot2")
## End(Not run)
function to check value of ggproto
Description
function to check all classes of a ggproto function
Usage
check_ggproto(value)
Arguments
value |
- ggproto functions from the target package |
Check that the provided weights are numeric and non-negative.
Description
Check that the provided weights are numeric and non-negative.
Usage
check_risk_weights(weights)
Arguments
weights |
vector with weight values |
Function to check suggested exported functions
Description
This function checks the exported functions of target package against the exported functions of Suggested dependencies to see if any Suggested packages should be in Imports in the DESCRIPTION file
Usage
check_suggested_exp_funcs(pkg_name, pkg_source_path, suggested_deps)
Arguments
pkg_name |
- name of the target package |
pkg_source_path |
- source of the target package |
suggested_deps |
- dependencies in Suggests |
Value
- data frame with results of Suggests check
Check for Vignette Folder and .Rmd Files in a .tar File
Description
This function checks if a given .tar file contains a 'vignettes' folder
and if there is at least one .Rmd file within that folder. If both 'vignettes'
and 'inst/doc' folders exist, the function will return FALSE
.
Usage
contains_r_folder(package_dir)
Arguments
package_dir |
A character string specifying the path to the package to be checked. |
Details
The function checks if the specified folder exists. If 'R'
folder does not exist, the function returns FALSE
.
If the R folder exists, the function returns TRUE
.
Value
A logical value: TRUE
if the 'R' folder exists, FALSE
otherwise.
Check for Vignette Folder and .Rmd Files in a .tar File
Description
This function checks if a given .tar file contains a 'vignettes' folder
and if there is at least one .Rmd file within that folder. If both 'vignettes'
and 'inst/doc' folders exist, the function will return FALSE
.
Usage
contains_vignette_folder(tar_file)
Arguments
tar_file |
A character string specifying the path to the .tar file to be checked. |
Details
The function checks if the specified file exists and has a valid .tar extension using utils::untar
. If the file is empty or
any error occurs during the extraction, the function stops and returns an error message. If both 'vignettes'
and 'inst/doc' folders exist, the function returns FALSE
. If the 'vignettes' folder exists and contains
at least one .Rmd file, the function returns TRUE
. Otherwise, it returns FALSE
.
Value
A logical value: TRUE
if the 'vignettes' folder exists and contains at least one .Rmd file,
and neither 'vignettes' nor 'inst/doc' folders are present, FALSE
otherwise.
Examples
## Not run:
tar_file <- system.file("test-data", "here-1.0.1.tar.gz",
package = "risk.assessr")
result <- contains_vignette_folder(tar_file)
print(result)
## End(Not run)
Convert Abbreviated Numbers to Integers
Description
Converts a string containing a number with optional 'K' or 'M' abbreviation into an integer.
Usage
convert_abbreviation_to_number(value)
Arguments
value |
A character string representing a number (e.g., '1.2M', '500K', '100'). |
Value
An integer representation of the numeric value.
Create empty results
Description
This creates an empty results list for all risk metrics
Usage
create_empty_results(pkg_name, pkg_ver, pkg_source_path, metadata)
Arguments
pkg_name |
package name |
pkg_ver |
package version |
pkg_source_path |
package source path |
metadata |
list with metadata |
Value
- list with empty risk profile values
create empty tm
Description
create empty tm
Usage
create_empty_tm(pkg_name)
Arguments
pkg_name |
- name of package |
Value
empty_tm - list with no tm
Generate file coverage df
Description
Generates file coverage df when errors list created.
Usage
create_file_coverage_df(file_names, file_coverage, errors, notes)
Arguments
file_names |
- file names |
file_coverage |
- test coverage for files |
errors |
- test coverage errors |
notes |
- test coverage notes |
Create items matched
Description
create a df with functions that match exported functions from a suggested package
Usage
create_items_matched(extracted_functions, suggested_exp_func)
Arguments
extracted_functions |
- exported functions from the target package |
suggested_exp_func |
- exported functions from a suggested package |
Create risk profile
Description
This creates a risk profile for all risk metrics
Usage
create_risk_profile()
Value
- list with risk profile values
Create a Traceability Matrix
Description
Returns a table that links all exported functions and their aliases to their documentation ('man' files), the R scripts containing them, and the test scripts that reference them.
Usage
create_traceability_matrix(
pkg_name,
pkg_source_path,
func_covr,
verbose = FALSE
)
Arguments
pkg_name |
name of package |
pkg_source_path |
path to a source package |
func_covr |
function coverage |
verbose |
Logical ('TRUE'/'FALSE'). If 'TRUE', show any warnings/messages per function. |
Value
a tibble with traceability matrix
Create weights profile
Description
This creates a specific weights profile for all risk metrics
Usage
create_weights_profile()
Value
- numeric vector with weights profile
Examples
create_weights_profile()
Run all relevant documentation riskmetric checks
Description
Run all relevant documentation riskmetric checks
Usage
doc_riskmetric(pkg_name, pkg_ver, pkg_source_path)
Arguments
pkg_name |
name of the package |
pkg_ver |
version of the package |
pkg_source_path |
path to package source code (untarred) |
Value
raw riskmetric outputs
Extract aria-label from SVG data
Description
Extracts the aria-label attribute value from SVG data badge.
Usage
extract_aria_label(svg_data)
Arguments
svg_data |
A character string containing SVG data. |
Value
A character string containing the extracted aria-label value, or NULL if not found.
function to extract ggproto methods
Description
function to get all the methods of a ggproto function
Usage
extract_ggproto_methods(obj)
Arguments
obj |
- ggproto env from the target package |
Extract package name from package source path
Description
Extract package name from package source path
Usage
extract_package_name(pkg_source_path)
Arguments
pkg_source_path |
a file path pointing to an unpacked/untarred package directory |
Value
package_name
Extract Package Version from File Path
Description
This function extracts the version number from a package source file name based on the package name and expected file pattern.
Usage
extract_version(path, package_name)
Arguments
path |
A character string specifying the file path or URL. |
package_name |
A character string specifying the name of the package. |
Value
A character string representing the extracted version number, or 'NULL' if no match is found.
Examples
## Not run:
link <- "https://bioconductor.org/packages/3.14/bioc/src/contrib/GenomicRanges_1.42.0.tar.gz"
extract_version(link, "GenomicRanges")
## End(Not run)
Fetch Bioconductor Package Information
Description
This function retrieves information about a specific Bioconductor package for a given Bioconductor version. It fetches the package details, such as version, source package URL, and archived versions if available.
Usage
fetch_bioconductor_package_info(bioconductor_version, package_name)
Arguments
bioconductor_version |
A character string specifying the Bioconductor version (e.g., "3.14"). |
package_name |
A character string specifying the name of the package. |
Value
A list containing package details, including the latest version, package URL, source package link, and any archived versions if available. Returns 'FALSE' if the package does not exist or cannot be retrieved.
Examples
## Not run:
fetch_bioconductor_package_info("3.14", "GenomicRanges")
## End(Not run)
Fetch Bioconductor Release Announcements
Description
This function retrieves the Bioconductor release announcements page and returns its HTML content for further processing.
Usage
fetch_bioconductor_releases()
Value
An XML document from bioconductor version page.
Examples
## Not run:
html_content <- fetch_bioconductor_releases()
## End(Not run)
Remove specific symbols from vector of functions
Description
adapted from mpn.scorecard
adapted from mpn.scorecard
Usage
filter_symbol_functions(funcs)
filter_symbol_functions(funcs)
Arguments
funcs |
vector of functions to filter |
find reverse dependencies
Description
find reverse dependencies
Usage
find_reverse_dependencies(path)
Arguments
path |
pkg_ref path |
function to check value of ggproto
Description
function to check if first argument inherits from any of the classes specified
Usage
function_is_ggproto(x)
Arguments
x |
- ggproto functions from the target package |
Generate Coverage Section
Description
Generates the Coverage section for the HTML report.
Usage
generate_coverage_section(assessment_results)
Arguments
assessment_results |
- input data |
Generate Dependencies Section
Description
Generates the dependencies section for the HTML report.
Usage
generate_deps_section(assessment_results)
Arguments
assessment_results |
- input data |
Generate Doc Metrics Section
Description
Generates the documentation section for the HTML report.
Usage
generate_doc_metrics_section(assessment_results)
Arguments
assessment_results |
- input data |
Generate HTML Report for Package Assessment
Description
Generates an HTML report for the package assessment results using rmarkdown.
Usage
generate_html_report(assessment_results, output_dir)
Arguments
assessment_results |
List containing the results from risk_assess_pkg function. |
output_dir |
Character string indicating the directory where the report will be saved. |
Value
Path to the generated HTML report.
Examples
## Not run:
assessment_results <- risk_assess_pkg()
generate_html_report(assessment_results, output_dir = "path/to/save/report")
## End(Not run)
Generate RCMD Check Metrics Section
Description
Generates the RCMD Check Metrics HTML table for the HTML report.
Usage
generate_rcmd_check_section(assessment_results)
Arguments
assessment_results |
- input data |
Generate Reverse Dependencies Section
Description
Generates the reverse dependencies section for the HTML report.
Usage
generate_rev_deps_section(assessment_results)
Arguments
assessment_results |
- input data |
Generate Risk Details
Description
Generates the Risk Details table for the HTML report.
Usage
generate_risk_details(assessment_results)
Arguments
assessment_results |
- input data |
Generate Risk Summary
Description
Generates the Risk Summary table for the HTML report.
Usage
generate_risk_summary(assessment_results)
Arguments
assessment_results |
- input data |
Generate Trace Matrix Section
Description
Generates the Trace Matrix section for the HTML report.
Usage
generate_trace_matrix_section(assessment_results)
Arguments
assessment_results |
- input data |
Retrieve Bioconductor Package URL
Description
This function fetches the source package URL for a given Bioconductor package. If no version is specified, it retrieves the latest available version. Currently, this function is not able to fetch archived package version for a bioconductor version
Usage
get_bioconductor_package_url(
package_name,
package_version = NULL,
release_data
)
Arguments
package_name |
A character string specifying the name of the Bioconductor package. |
package_version |
(Optional) A character string specifying the package version. Defaults to 'NULL', which retrieves the latest version. |
release_data |
A list containing Bioconductor release information. |
Value
A list containing the following elements:
url |
The URL of the source package (if available). |
version |
The specified or latest available package version. |
last_version |
The last available version of the package. |
all_versions |
A vector of all discovered versions of the package. |
bioconductor_version_package |
The Bioconductor version associated with the package. |
archived |
A logical value indicating whether the package is archived. |
Examples
## Not run:
release_data <- list(
list(release = "3.12"),
list(release = "3.13"),
list(release = "3.14")
)
get_bioconductor_package_url("GenomicRanges", release_data = release_data)
## End(Not run)
Get CRAN Package URL
Description
This function constructs the CRAN package URL for a specified package and version.
Usage
get_cran_package_url(package_name, version, last_version, all_versions)
Arguments
package_name |
A character string specifying the name of the package. |
version |
An optional character string specifying the version of the package. |
last_version |
A character string specifying the latest available version of the package. |
all_versions |
A character vector of all available versions of the package. |
Value
A character string containing the URL to download the package tarball, or 'NULL' if the version is not found in the list of available versions.
Examples
url_result <- get_cran_package_url("dplyr", NULL, "1.0.10", c("1.0.0", "1.0.10"))
list all package exports
Description
adapted from mpn.scorecard
adapted from mpn.scorecard
Usage
get_exports(pkg_source_path)
get_exports(pkg_source_path)
Arguments
pkg_source_path |
a file path pointing to an unpacked/untarred package directory |
Value
data.frame, with one column 'exported_function', that can be passed to all downstream map_* helpers
data.frame, with one column 'exported_function', that can be passed to all downstream map_* helpers
Get function descriptions
Description
get descriptions of exported functions
Usage
get_func_descriptions(pkg_name)
Arguments
pkg_name |
- name of the package |
Fetch GitHub Repository Data
Description
This function retrieves metadata about a GitHub repository, including creation date, stars, forks, and the number of recent commits within the last 30 days.
Usage
get_github_data(owner, repo)
Arguments
owner |
A character string specifying the owner of the repository (e.g., GitHub username). |
repo |
A character string specifying the name of the repository. A github Personal Access Token (PAT) will be needed for some request or to help with the rate limit. Use Sys.setenv(GITHUB_TOKEN = "personal_access_token") or store your token in a .Renviron file (GitHub fine grained token are not yet covered by gh) |
Details
If the 'owner' parameter is 'NA' or empty, the function returns an empty response object. Repository data is fetched using the GitHub API via the 'gh' package.
Value
A list containing: - 'created_at': Creation date of the repository. - 'stars': Number of stars the repository - 'forks': Number of forks of the repository. - 'date': acquisition date in the format "YYYY-MM-DD". - 'recent_commits_count': count of commits in the last 30 days (from acquisition date).
Examples
## Not run:
# Fetch data for the "ggplot2" repository owned by "tidyverse"
result <- get_github_data("tidyverse", "ggplot2")
print(result)
## End(Not run)
Extract and Validate Package Hosting Information
Description
This function retrieves hosting links for an R package from various sources such as GitHub, CRAN, internal repositories, or Bioconductor.
Usage
get_host_package(pkg_name, pkg_version, pkg_source_path)
Arguments
pkg_name |
Character. The name of the package. |
pkg_version |
Character. The version of the package. |
pkg_source_path |
Character. The file path to the package source directory containing the DESCRIPTION file. |
Details
The function extracts hosting links by: 1. Parsing the 'DESCRIPTION' file for GitHub and BugReports URLs. 2. Checking if the package is valid on CRAN and others host repository
If no links are found in the 'DESCRIPTION' file, returns 'NULL'
Value
A list containing the following elements:
- 'github_links': GitHub links related to the package. - 'cran_links': CRAN links - 'internal_links': internal repository links. - 'bioconductor_links': Bioconductor links
If links are found, return empty or NULL.
Get Internal Package URL
Description
This function retrieves the URL of an internal package on your internal Mirror, its latest version, and a list of all available versions.
Usage
get_internal_package_url(
package_name,
version = NULL,
base_url = "http://cran.us.r-project.org",
internal_path = "/src/contrib/"
)
Arguments
package_name |
A character string specifying the name of the package. |
version |
An optional character string specifying the version of the package. Defaults to 'NULL', in which case the latest version will be used. |
base_url |
a character string of internal package manager link |
internal_path |
a character string of internal package mirror link |
Value
A list containing: - 'url': A character string of the package URL (or 'NULL' if not found). - 'last_version': A character string of the latest version of the package. - 'all_versions': A character vector of all available package versions.
Examples
## Not run:
# Retrieve a specific version URL of a package
result <- get_internal_package_url("internalpackage", version = "1.0.1")
print(result)
## End(Not run)
Get CRAN Package Download Count
Description
Retrieves the download count for a given CRAN package from the CRAN logs API.
Usage
get_package_download(package_name, timeline = "grand-total")
Arguments
package_name |
A character string specifying the package name. |
timeline |
A character string specifying the timeline ('last-month', or 'grand-total'). |
Value
An integer representing the total number of downloads.
Examples
## Not run:
total_download_result <- get_package_download('ggplot2')
month_download_result <- get_package_download('dplyr', 'last-month')
## End(Not run)
Assess Authors
Description
Assess Authors
Usage
get_pkg_author(pkg_name, pkg_source_path)
Arguments
pkg_name |
- name of the package |
pkg_source_path |
- source path for install local |
Value
- Authors related variable
check for package creator
Description
check for package creator
Usage
get_pkg_creator_info(pkg_name, pkg_source_path)
Arguments
pkg_name |
- package name |
pkg_source_path |
- path to package |
Value
- logical - package creator exists - 'FALSE'
Read Description file and parse the package name and version
Description
Read Description file and parse the package name and version
Usage
get_pkg_desc(pkg_source_path, fields = NULL)
Arguments
pkg_source_path |
path to package source code (untarred) |
fields |
- select specified elements from description |
Value
list with package description
Assess License
Description
Assess License
Usage
get_pkg_license(pkg_name, pkg_source_path)
Arguments
pkg_name |
- name of the package |
pkg_source_path |
- source path for install local |
Value
- Authors related variable
get package name for display
Description
get package name for display
Usage
get_pkg_name(input_string)
Arguments
input_string |
- string containing package name |
Value
pkg_disp - package name for display
Examples
pkg_source_path <- "/home/user/R/test.package.0001_0.1.0.tar.gz"
pkg_disp_1 <- get_pkg_name(pkg_source_path)
print(pkg_disp_1)
pkg <- "TxDb.Dmelanogaster.UCSC.dm3.ensGene_3.2.2.tar.gz"
pkg_disp_2 <- get_pkg_name(pkg)
print(pkg_disp_2)
get regular function bodies
Description
create a tibble with regular function bodies
Usage
get_regular_function_body(pkg_name, func_name)
Arguments
pkg_name |
- name of the package |
func_name |
- current function |
Extract GitHub repository owner from links
Description
Given a vector of GitHub links and a package name, this function finds the link corresponding to the package and extracts the GitHub repository owner.
Usage
get_repo_owner(links, pkg_name)
Arguments
links |
A character vector of GitHub URLs. |
pkg_name |
A string representing the name of the package. |
Value
A string containing the GitHub repository owner, or NA if not found.
Assign output file path for various outputs during scorecard rendering
Description
Assign output file path for various outputs during scorecard rendering
Usage
get_result_path(
out_dir,
ext = c("check.rds", "covr.rds", "tm_doc.rds", "tm_doc.xlsx")
)
Arguments
out_dir |
output directory for saving results |
ext |
file name and extension |
Details
The basename of 'out_dir' should be the package name and version pasted together
Get risk metadata
Description
Get risk metadata
Usage
get_risk_metadata(executor = NULL)
Arguments
executor |
- user who executes the riskmetrics process adapted from mrgvalprep::get_sys_info() and mpn.scorecard |
Value
list with metadata
function to get S3 method
Description
function to get S3 method from generic
Usage
get_s3_method(generic, class, package)
Arguments
generic |
- function generic |
class |
- function class |
package |
- package name |
Get Dependencies
Description
This function extracts the version information of imported and suggested packages for a given package from the current R session.
Usage
get_session_dependencies(deps_list)
Arguments
deps_list |
A data frame containing the dependency information of the package (provided by calc_dependencies function) |
Value
A list with two elements:
imports |
A named list of packages in the "Imports" section along with their corresponding versions |
suggests |
A named list of packages in the "Suggests" section along with their corresponding versions |
Examples
deps_list <- data.frame(
package = c("dplyr", "ggplot2", "testthat", "knitr"),
type = c("Imports", "Imports", "Suggests", "Suggests")
)
get_session_dependencies(deps_list)
Function to get suggested exported functions
Description
This function gets exported functions for all packages in the Suggests section of the target package's DESCRIPTION file
Usage
get_suggested_exp_funcs(data)
Arguments
data |
- all packages listed in the DESCRIPTION file |
Value
- data with package names and exported functions
list all top-level objects defined in the package code
Description
adapted from mpn.scorecard
adapted from mpn.scorecard
Usage
get_toplevel_assignments(pkg_source_path)
get_toplevel_assignments(pkg_source_path)
Arguments
pkg_source_path |
a file path pointing to an unpacked/untarred package directory |
Details
This is primarily for getting all _functions_, but it also returns top-level declarations, regardless of type. This is intentional, because we also want to capture any global variables or anything else that could be potentially exported by the package.
This is primarily for getting all _functions_, but it also returns top-level declarations, regardless of type. This is intentional, because we also want to capture any global variables or anything else that could be potentially exported by the package.
Value
A data.frame with the columns 'function' and 'code_script' with a row for every top-level object defined in the package.
A data.frame with the columns 'function' and 'code_script' with a row for every top-level object defined in the package.
Get Package Versions
Description
This function retrieves all available versions including last version from parse_html_version function'
Usage
get_versions(table, package_name)
Arguments
table |
A list of parsed package data, where each element contains package details including package_version. |
package_name |
A character string specifying the name of the package to fetch versions for. |
Value
A list containing: - 'all_versions': A character vector of all unique package versions. - 'last_version': A character string of the latest version fetched from the RStudio Package Manager, or 'NULL' if not available.
Examples
## Not run:
# Define the input table
table <- list(
list(
package_name = "here",
package_version = "0.1",
link = "here_0.1.tar.gz",
date = "2017-05-28 08:13",
size = "3.5K"
),
list(
package_name = "here",
package_version = "1.0.0",
link = "here_1.0.0.tar.gz",
date = "2020-11-15 18:10",
size = "32K"
)
)
# Use the get_versions function
result <- get_versions(table, "here")
# Example output
print(result)
## End(Not run)
Install package locally
Description
Install package locally
Usage
install_package_local(pkg_source_path)
Arguments
pkg_source_path |
- source path for install local |
Value
logical. Returns 'TRUE' if the package was successfully installed, 'FALSE' otherwise.
Examples
## Not run:
results <- install_package_local("pkg_source_path")
print(results)
## End(Not run)
Map all Rd files to the functions they describe
Description
adapted from mpn.scorecard
Usage
map_functions_to_docs(exports_df, pkg_source_path, verbose)
Value
Returns the data.frame passed to 'exports_df', with a 'documentation' column appended. This column will contain the path to the '.Rd' files in 'man/' that document the associated exported functions.
Get all exported functions and map them to R script where they are defined
Description
adapted from mpn.scorecard
adapted from mpn.scorecard
Usage
map_functions_to_scripts(exports_df, pkg_source_path, verbose)
map_functions_to_scripts(exports_df, pkg_source_path, verbose)
Arguments
exports_df |
data.frame with a column, named 'exported_function', containing the names of all exported functions. Can also have other columns (which will be returned unmodified). |
pkg_source_path |
a file path pointing to an unpacked/untarred package directory |
verbose |
check for extra information |
Value
A data.frame with the columns 'exported_function' and 'code_script'.
A data.frame with the columns 'exported_function' and 'code_script'.
Modify the DESCRIPTION File in a R Package Tarball
Description
This function recreate a '.tar.gz' R package file after modifying its 'DESCRIPTION' file by appending Config/build/clean-inst-doc: false parameter.
Usage
modify_description_file(tar_file)
Arguments
tar_file |
A string representing the path to the '.tar.gz' file that contains the R package. |
Value
A string containing the path to the newly created modified '.tar.gz' file.
Examples
## Not run:
modified_tar <- modify_description_file("path/to/mypackage.tar.gz")
print(modified_tar)
## End(Not run)
Parse Bioconductor Release Announcements
Description
This function extracts Bioconductor release details such as version number, release date, number of software packages, and required R version from the release announcements HTML page.
Usage
parse_bioconductor_releases(html_content)
Arguments
html_content |
The parsed HTML document from 'fetch_bioconductor_releases'. |
Value
A list of lists containing Bioconductor release details: release version, date, number of software packages, and corresponding R version.
Examples
## Not run:
html_content <- fetch_bioconductor_releases()
release_data <- parse_bioconductor_releases(html_content)
## End(Not run)
Parse DCF of description file
Description
Parse DCF of description file
Usage
parse_dcf_dependencies(path)
Arguments
path |
pkg_ref path |
Parse HTML Content for Package Versions
Description
This function extracts version information from an HTML page listing available versions of a Bioconductor package.
This function extracts version information from the HTML content of a CRAN archive page.
Usage
parse_html_version(html_content, package_name)
parse_html_version(html_content, package_name)
Arguments
html_content |
A character string containing the HTML content of a CRAN package archive page. |
package_name |
A character string specifying the name of the package to extract version information for. |
Value
A list of lists containing package details such as package name, version, link, date, and size. Returns an empty list if no versions are found.
A list of lists, where each sublist contains: - 'package_name': package name. - 'package_version': package version. - 'link': link to the package tarball. - 'date': The date associated with the package version. - 'size': The size of the package tarball.
Examples
## Not run:
parse_html_version(html_content, "GenomicRanges")
## End(Not run)
Parse Package Information from CRAN Archive
Description
This function retrieves the package archive information from the CRAN Archive.
Usage
parse_package_info(name)
Arguments
name |
A character string specifying the name of the package to fetch information for. |
Value
A character string containing the raw HTML content of the package archive page, or 'NULL' if the request fails or the package is not found.
Examples
## Not run:
# Fetch package archive information for "dplyr"
result <- parse_package_info("dplyr")
print(result)
## End(Not run)
function to preprocess func_full_name
Description
function to extract package, class, and generic
Usage
preprocess_func_full_name(func_full_name)
Arguments
func_full_name |
- full name of the function |
process items matched
Description
create a df with functions that match exported functions from a suggested package
Usage
process_items_matched(items_matched, suggested_exp_func)
Arguments
items_matched |
- exported functions match the suggested package function |
suggested_exp_func |
- exported functions from a suggested package |
Details
This function extracts all the functions from the function body and filters them to keep only function calls It also extracts all the valid function names, matches with the source package and writes a message
Re-calculate package risk scores
Description
Use this function to re-calculate risk scores and risk profile
Usage
recalc_risk_scores(riskdata_results, update_comments)
Arguments
riskdata_results |
- path to riskdata_results toy dataset |
update_comments |
notes explaining why score recalculated |
Details
Use cases: if the weighting profile and/or risk profile thresholds have changed and the risk metrics have not changed, then use this function to re-calculate the risk scores and profile without running the whole risk assessment process again
Value
A dataframe containing both the original and newly calculated risk scores, profiles, and comments.
Helper function to remove base and recommended packages
Description
Helper function to remove base and recommended packages
Usage
remove_base_packages(df)
Arguments
df |
Data frame of dependencies of a package. |
Assess package - simplified
Description
simplified input to assess package for risk metrics
Usage
risk_assess_pkg(path = NULL)
Arguments
path |
(optional) path of locally stored package source code |
Value
list containing results - list containing metrics, covr, tm - trace matrix, and R CMD check
Examples
## Not run:
risk_assess_package <- risk_assess_pkg()
OR
risk_assess_package <- risk_assess_pkg(path/to/package.tar.gz)
## End(Not run)
Process lock files
Description
This function processes 'renv.lock' and 'pak.lock' files to produce risk metric data
Usage
risk_assess_pkg_lock_files(input_data)
Arguments
input_data |
- path to a lock file |
Value
assessment_results - nested list containing risk metric data
Examples
## Not run:
input_data <- ("path/to/mypak.lock")
pak_results <- risk_assess_pkg_lock_files(input_data)
print(pak_results)
## End(Not run)
Run covr and potentially save results to disk
Description
Run covr and potentially save results to disk
Usage
run_coverage(pkg_source_path, timeout = Inf)
Arguments
pkg_source_path |
package installation directory |
timeout |
Timeout to pass to [callr::r_safe()] when running covr. |
Value
list with total coverage and function coverage
Run covr in subprocess with timeout
Description
Run covr in subprocess with timeout
Usage
run_covr(path, timeout)
Arguments
path |
- path to source file |
timeout |
- length of timeout - set to Inf |
Run R CMD CHECK
Description
Run R CMD CHECK
Usage
run_rcmdcheck(pkg_source_path, rcmdcheck_args)
Arguments
pkg_source_path |
directory path to R project |
rcmdcheck_args |
list of arguments to pass to 'rcmdcheck::rcmdcheck' |
Details
rcmdcheck takes either a tarball or an installation directory.
The basename of 'pkg_source_path' should be the package name and version pasted together
The returned score is calculated via a weighted sum of notes (0.10), warnings (0.25), and errors (1.0). It has a maximum score of 1 (indicating no errors, notes or warnings) and a minimum score of 0 (equal to 1 error, 4 warnings, or 10 notes). This scoring methodology is taken directly from [riskmetric::metric_score.pkg_metric_r_cmd_check()].
Score a package for dependencies
Description
Calculates a regularized score based on the number of dependencies a package has.
Convert the number of dependencies NROW(x)
into a validation
score [0,1]
1 / (1 + exp(-0.5 * (NROW(x) + 19)))
Usage
score_dependencies(x)
Arguments
x |
number of dependencies |
Details
removed - 1 from the formula e.g.
1 - 1 / (1 + exp(NROW(x)- 19))
to reverse the return value e.g. 0 - low; 1 - high
The scoring function is the classic logistic curve
/ (1 + exp(-k(x-x[0]))
x = NROW(x)
, sigmoid midpoint is 20 reverse dependencies, ie. x[0] = 19
,
and logistic growth rate of k = 0.5
.
1 / (1 + exp(NROW(x)- 19))
Value
numeric value between 0
(low number of dependencies) and
1
(high number of dependencies)
Scoring method for number of reverse dependencies a package has
Description
Score a package for the number of reverse dependencies it has; regularized
Convert the number of reverse dependencies length(x)
into a validation
score [0,1]
1 / (1 + exp(-0.5 * (sqrt(length(x)) + sqrt(20))))
Usage
score_reverse_dependencies(x)
Arguments
x |
number of dependencies |
Details
The scoring function is the classic logistic curve
1 / (1 + exp(-k(x-x[0]))
with a square root scale for the number of reverse dependencies
x = sqrt(length(x))
, sigmoid midpoint is 20 reverse dependencies, ie. x[0] =
sqrt(15)
, and logistic growth rate of k = 0.5
.
1 / (1 + -0.5 * exp(sqrt(length(x)) - sqrt(20)))
Value
numeric value between 1
(high number of reverse dependencies) and
0
(low number of reverse dependencies)
Creates information on package installation
Description
Creates information on package installation
Usage
set_up_pkg(dp, check_type = "1")
Arguments
dp |
data path and name for the package. |
check_type |
basic R CMD check type - "1" CRAN R CMD check_type - "2" |
Value
list with local package install
Examples
## Not run:
set_up_pkg(path/to/package, "mypackage")
## End(Not run)
set up rcmdcheck arguments
Description
This sets up rcmdcheck arguments
Usage
setup_rcmdcheck_args(check_type = "1", build_vignettes)
Arguments
check_type |
basic R CMD check type - "1" CRAN R CMD check_type - "2" |
build_vignettes |
Logical (T/F). Whether or not to build vignettes |
Details
Some packages need to have build vignettes as a build argument as their vignettes structure is inst/doc or inst/docs
Value
- list with rcmdcheck arguments
Check weights values and standardize them.
Description
Check weights values and standardize them.
Usage
standardize_risk_weights(data, weights)
Arguments
data |
risk metric data |
weights |
vector with weight values |
Untar package and return installation directory
Description
Untar package and return installation directory
Usage
unpack_tarball(pkg_tar, temp_file_name = "temp_file_")
Arguments
pkg_tar |
path to tarball package |
temp_file_name |
name of 'tempfile' |
update pscore results
Description
This updates results list for pscore risk metrics
Usage
update_pscore_results(results, pscore)
Arguments
results |
list with results |
pscore |
results from open source risk metrics |
Value
- list with updated risk result values
update results doc_metrics
Description
This updates results list for documentation risk metrics
Usage
update_results_doc_scores(results, doc_scores)
Arguments
results |
list with results |
doc_scores |
results from documentation risk metrics |
Value
- list with updated risk result values