Title: Assessing Package Risk Metrics
Version: 3.0.0
Description: A reliable and validated tool that captures detailed risk metrics such as R 'CMD' check, test coverage, traceability matrix, documentation, dependencies, reverse dependencies, suggested dependency analysis, repository data, and enhanced reporting for R packages that are local or stored on remote repositories such as GitHub, CRAN, and Bioconductor.
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, dplyr, fs, methods, purrr, rmarkdown, rcmdcheck, rlang, xml2, stringr, tidyr, utils, curl, jsonlite, memoise, BiocManager
Suggests: devtools, forcats, glue, here, htmltools, htmlwidgets, kableExtra, knitr, magrittr, openxlsx, R6, S7, readr, roxygen2, testthat (≥ 3.0.0), tidyselect, tools, withr, mockery, ggplot2, DT
Encoding: UTF-8
RoxygenNote: 7.3.2
Config/testthat/edition: 3
Config/build/clean-inst-doc: false
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2025-11-28 11:11:56 UTC; u1004798
Author: Edward Gillian ORCID iD [cre, aut], Hugo Bottois ORCID iD [aut], Paulin Charliquart [aut], Andre Couturier [aut], Sanofi [cph, fnd]
Maintainer: Edward Gillian <edward.gillian-ext@sanofi.com>
Repository: CRAN
Date/Publication: 2025-11-28 11:50:02 UTC

risk.assessr: Assessing Package Risk Metrics

Description

logo

A reliable and validated tool that captures detailed risk metrics such as R 'CMD' check, test coverage, traceability matrix, documentation, dependencies, reverse dependencies, suggested dependency analysis, repository data, and enhanced reporting for R packages that are local or stored on remote repositories such as GitHub, CRAN, and Bioconductor.

Author(s)

Maintainer: Edward Gillian edward.gillian-ext@sanofi.com (ORCID)

Authors:

Other contributors:

See Also

Useful links:


Convert input to ISO 8601 date (YYYY-MM-DD)

Description

Formats inputs as ISO 8601 calendar dates ('"YYYY-MM-DD"').

Usage

as_iso_date(x)

Arguments

x

A vector coercible to 'Date' (e.g., character, 'Date', or 'POSIXct'). If 'NULL', the function returns 'NULL'.

Details

Coercion uses [base::as.Date()], so time-of-day and timezone information are dropped. For 'POSIXct' inputs, the date is computed by 'as.Date.POSIXct' (which uses 'tz = "UTC"' by default). Be aware that ambiguous character dates (e.g., '"01/02/2024"') depend on your R locale/format unless you specify a format before calling this function.

Value

A character vector the same length as 'x' (or 'NULL' if 'x' is 'NULL') with dates formatted as '"YYYY-MM-DD"'. Unparseable elements or 'NA's become 'NA_character_'.

Examples

as_iso_date(Sys.Date())
as_iso_date(NULL)              
as_iso_date("not-a-date")


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 mirrors

Details

This function follows these steps:

  1. Downloads the specified R package

  2. Installs the downloaded package in a temporary location.

  3. Runs the 'risk.assessr::assess_pkg' function to assess the package for risks and issues.

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


r <- getOption("repos")
# save current repo options  
old <- options(repos = r)
r["CRAN"] = "http://cran.us.r-project.org"
options(repos = r)#' 

results <- assess_pkg_r_package("here", version = "1.0.1")

# restore user's repo options
options(old)

print(results)



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 Average Time to Close GitHub Issues

Description

This function uses the GitHub API to retrieve closed issues from a repository and calculates the average time (in hours) it took to close them, excluding pull requests.

Usage

average_issue_close_time(
  owner,
  repo,
  max_pages = 10,
  per_page = 100,
  headers = c(Accept = "application/vnd.github.v3+json")
)

Arguments

owner

Character. GitHub organization or username.

repo

Character. Repository name.

max_pages

Integer. Maximum number of API result pages to query. Each page can contain up to 'per_page' issues. Default is 10.

per_page

Integer. Number of issues to request per page (max 100). Default is 100.

headers

Named character vector of HTTP headers to send with the API request. Default sets GitHub API version.

Value

Numeric. Average time in hours to close issues, or 'NA' if no closed issues were found.

Examples

## Not run: 
average_issue_close_time("tidyverse", "ggplot2")

## End(Not run)

Find Bioconductor Package Reverse Dependencies

Description

This function returns the reverse dependencies for a given Bioconductor package.

Usage

bioconductor_reverse_deps(
  pkg,
  which = "Imports",
  only.bioc = FALSE,
  version = BiocManager::version(),
  db = NULL,
  biocdb = NULL
)

Arguments

pkg

Character string. The name of the package for which to find reverse dependencies.

which

Character vector. The dependency categories to check. One or more of "Depends", "Imports", "LinkingTo", "Suggests", or "Enhances". Defaults to "Imports".

only.bioc

Logical. If TRUE (default), only reverse dependencies that are Bioconductor packages are returned.

version

Bioconductor version to use. Defaults to the current version.

db

Optional. A pre-loaded package database to use for lookups.

biocdb

Optional. A pre-loaded Bioconductor package database.

Value

A named list of reverse dependency package names.

Examples


# Get reverse Imports dependencies as a list:
bioconductor_reverse_deps("limma")

# Get multiple categories:
bioconductor_reverse_deps("limma", which = c("Depends", "Suggests"))


Build a Dependency Tree for an R Package

Description

This function constructs a nested list representing the dependency tree of a specified R package. The recursion stops at a depth of 3 levels (or until base package).

Usage

build_dependency_tree(package_name, level = 1)

Arguments

package_name

A character string specifying the name of the package.

level

An integer indicating the current recursion depth (default: 1).

Value

A nested list representing the dependency tree, where base packages are marked as "base".

Examples

## Not run: 
build_dependency_tree("ggplot2")

## End(Not run)


Capture CRAN URL warnings and errors

Description

This internal function attempts to open a CRAN URL and read its contents. It captures and classifies warnings and errors related to network issues, such as timeouts or inaccessible URLs.

Usage

capture_cran_warning(cran_url, path)

Arguments

cran_url

Character. Base URL of the CRAN mirror.

path

Character. Path to the resource on the CRAN server.

Value

A list with two elements:

status

Character string indicating the result type: "success", "url_error", "timeout", "error", "url_warning", "timeout_warning", or "warning".

message

Character string with the captured warning or error message, or NULL if successful.

Examples

## Not run: 
  capture_cran_warning("http://cran.us.r-project.org", "src/contrib/Meta/archive.rds")

## 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 with one of the following structures:

package_url

Character string; the URL to download the package tarball.

last_version

A named list with version and date for the latest available version.

version

Character string; the requested version (or NULL if not specified).

all_versions

A list of named lists, each with version and date, representing all available versions.

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)

Reclassify Forbidden Notes as Errors in rcmdcheck Results

Description

This internal helper function scans the 'notes' field of an 'rcmdcheck' result object for specific patterns that indicate more serious issues. If any of these patterns are found, the corresponding notes are reclassified as errors by moving them from the 'notes' field to the 'errors' field.

Usage

check_forbidden_notes(res_check, pkg_name)

Arguments

res_check

A list representing the result of an 'rcmdcheck' run. It should contain at least the elements 'notes', 'warnings', and 'errors', each being a character vector.

pkg_name

name of the package

Value

A modified version of 'res_check' where certain notes matching forbidden patterns are moved to the 'errors' field.

Examples


pkg_name <- "foo"
res_check <- list(
  notes = c("'foo' import not declared from: 'bar'",
            "Namespace in Imports field not imported from: 'baz'",
            "no visible global function definition for 'qux'",
            "some harmless note"),
  warnings = character(0),
  errors = character(0)
)
updated <- check_forbidden_notes(res_check, pkg_name)
print(updated$errors)  # Should include the first three notes
print(updated$notes)   # Should include only the harmless note


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 for tests/testthat and _snaps folder and count golden tests

Description

Check for tests/testthat and _snaps folder and count golden tests

Usage

check_pkg_tests_and_snaps(pkg_source_path)

Arguments

pkg_source_path

Path to the root of the package source

Value

A list with: - 'has_testthat': Does tests/testthat exist? - 'has_testit': Does tests/testit exist? - 'has_snaps': Does _snaps exist inside tests/testthat? - 'n_golden_tests': Number of snapshot files inside _snaps - 'n_test_files': Number of test-*.R files inside tests/testthat


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


classify_function_body

Description

This function gets the function bodies for exported functions

Usage

classify_function_body(row, package_name)

Arguments

row

- row with exported functions

package_name

- name of the package

Value

row - row with the function details plus function body


Clean and normalize license names

Description

Splits a license string on commas, plus signs, or pipes, trims whitespace, removes trailing noise like "file LICENSE", and normalizes each part to uppercase letters only.

Usage

clean_license(x)

Arguments

x

A character string containing license information.

Value

A character vector of normalized license names.


Clean Up Dependencies

Description

Cleans up a list of dependency strings by extracting unique package names.

Usage

clean_up_dependencies(x)

Arguments

x

A character vector of dependency strings.

Value

A character vector of unique package names.


Compute Risk Level

Description

Apply risk thresholds to compute risk level for a single metric.

Usage

compute_risk(value, risk)

Arguments

value

The numeric or categorical value to evaluate.

risk

A list describing the thresholds for the metric.

Value

The computed risk level (e.g. "low", "medium", "high").


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 number to abbreviation

Description

Convert number to abbreviation

Usage

convert_number_to_abbreviation(value)

Arguments

value

Convert number to percent

Description

Convert number to percent

Usage

convert_number_to_percent(value)

Arguments

value

Count Commits in the Last Months

Description

Counts the total number of commits from the last 'months' months using a data frame with weekly commit data (column 'week_start').

Usage

count_commits_last_months(df, months = 1, today = Sys.Date())

Arguments

df

A data frame with 'week_start' (Date) and 'n_commits' (int) columns.

months

Integer. Number of months to look back (default is 1).

today

today's date.default is Sys.Date()

Value

Integer. Total number of commits in the time window.

Examples

## Not run: 
df <- get_commits_since("tidyverse", "ggplot2", years = 1)
count_commits_last_months(df, months = 3)

## End(Not run)

Retrieve the List of CRAN Packages (Internal)

Description

Downloads and caches the current list of packages available on CRAN.

Usage

cran_packages(cache = TRUE)

Arguments

cache

Logical. If TRUE (default), the result is cached using memoise::memoise() with a timeout of 30 minutes to avoid repeated downloads. If FALSE, the metadata is fetched directly from CRAN each time the function is called.

Details

The function downloads the packages.rds file from the CRAN website, which contains metadata about all available packages. The result is cached using memoise::memoise() with a timeout of 30 minutes.

Value

A matrix of package metadata similar to the output of utils::available.packages(), with package names as row names.

Examples


pkgs <- cran_packages()
head(rownames(pkgs))



Find Reverse Dependencies of a CRAN Package

Description

This function finds the reverse dependencies of a CRAN package, i.e., packages that depend on the specified package.

Usage

cran_revdep(
  pkg,
  dependencies = c("Depends", "Imports", "Suggests", "LinkingTo"),
  recursive = FALSE,
  ignore = NULL,
  installed = NULL
)

Arguments

pkg

A character string representing the name of the package.

dependencies

A character vector specifying the types of dependencies to consider. Default is c("Depends", "Imports", "Suggests", "LinkingTo").

recursive

A logical value indicating whether to find dependencies recursively. Default is FALSE.

ignore

A character vector of package names to ignore. Default is NULL.

installed

A matrix of installed packages.

Value

deps - A sorted character vector of package names that depend on the specified package.

Examples


cran_revdep("ggplot2")



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 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 = NULL,
  verbose = FALSE,
  execute_coverage = TRUE
)

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.

execute_coverage

Logical ('TRUE'/'FALSE'). If 'TRUE', execute test coverage.

Value

a nested list with fine grained traceability matrices

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)

dp <- system.file("test-data", "here-1.0.1.tar.gz", 
   package = "risk.assessr")

# Set up the package using the temporary file
install_list <- set_up_pkg(dp)

# 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)

# Get package name and version
pkg_desc <- get_pkg_desc(pkg_source_path, 
                         fields = c("Package", 
                                    "Version"))
pkg_name <- pkg_desc$Package
test_pkg_data <- check_pkg_tests_and_snaps(pkg_source_path)

covr_timeout <- Inf

if (test_pkg_data$has_testthat || test_pkg_data$has_testit) {
  
  covr_list <- run_coverage(
    pkg_source_path,  
    covr_timeout
  )    
} else {
  message("No testthat or testit configuration")
  covr_list <- list(
    total_cov = 0,
    res_cov = list(
      name = pkg_name,
      coverage = list(
        filecoverage = matrix(0, nrow = 1, dimnames = list("No functions tested")),
        totalcoverage = 0
      ),
      errors = "No testthat or testit configuration",
      notes = NA
    )
  )
}
# run without test coverage   
tm_list_no_covr <- create_traceability_matrix(pkg_name, 
                                      pkg_source_path,
                                      execute_coverage = FALSE)   
                                      
# run with test coverage                                         
tm_list_covr <- create_traceability_matrix(pkg_name, 
                                      pkg_source_path,
                                      covr_list$res_cov)
                                      
# run with test coverage parameter but no test coverage list                                        
tm_list_no_covr_list <- create_traceability_matrix(pkg_name, 
                                      pkg_source_path)   
                                         
options(old)

## End(Not run)


Determine Packages that Depend on Given Packages

Description

This function identifies packages that depend on the specified packages, considering various types of dependencies (e.g., strong, most, all).

Usage

dependsOnPkgs(
  pkgs,
  dependencies = "most",
  recursive = TRUE,
  lib.loc = NULL,
  installed = NULL
)

Arguments

pkgs

A character vector of package names to check dependencies for.

dependencies

A character string specifying the types of dependencies to consider. Can be "strong", "most", "all", or a custom vector of dependency types.

recursive

A logical value indicating whether to recursively check dependencies.

lib.loc

A character vector of library locations to search for installed packages.

installed

A matrix of installed packages, obtained from cran_packages function. .

Value

A character vector of package names that depend on the specified packages.

Examples


installed <- cran_packages()
dependsOnPkgs("here", installed = installed)



Detect Version Conflicts from dependency tree

Description

This function identifies duplicate version packages and reports conflicts.

Usage

detect_version_conflicts(pkg_list)

Arguments

pkg_list

A nested list structure from fetch_all_dependencies function

Value

A list of strings describing package version conflicts such as "Conflict in package cli: versions found - 3.6.2, 3.6.1" 'NULL' if no conflicts are found.

Examples

pkg_list <- list(
  ggplot2 = list(
    version = "3.5.1",
    cli = list(version = "3.6.2"),
    gtable = list(
      version = "0.3.4",
      cli = list(version = "3.6.1")
    )
  )
)
detect_version_conflicts(pkg_list)


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


Download and Parse Dependencies of an R Package

Description

This function downloads a specific version of an R package from a repository, extracts it, and parses its dependencies from the DESCRIPTION file.

Usage

download_and_parse_dependencies(package_name, version = NA)

Arguments

package_name

A character string representing the name of the package to download.

version

A character string specifying the version of the package to download. Defaults to 'NA', which fetches the latest version.

Value

A data frame containing: - 'package': The name of the dependency. - 'type': The type of dependency (e.g., "Imports"). - 'parent_package': The original package for which dependencies were parsed.

Examples

## Not run: 
download_and_parse_dependencies("dplyr")

## End(Not run)

Expand Dependency Type Specification

Description

Expands a dependency type specification into a character vector of dependency types.

Usage

expand_dependency_type_spec(x)

Arguments

x

A character string specifying the dependency type ("strong", "most", "all", or custom).

Value

A character vector of dependency types.


Extract Package Names from a Dependency String

Description

Parses a single package dependency string and extracts valid package names, excluding "R" and ignoring version constraints or comments.

Usage

extract_dependency_package_names(x)

Arguments

x

A character string representing a package dependency specification, such as '"pkgA (>= 1.0), pkgB, R (>= 3.5.0)"'.

Value

A character vector of package names extracted from the input string. The result excludes "R" and any version information.


Extract Exported Function Metadata from an R Package

Description

This internal utility function analyzes the namespace of an R package and extracts metadata about its exported functions, including classification into S3, S4, S7, and regular functions.

Usage

extract_exported_function_info(.pkg_source_path, package_name)

Arguments

.pkg_source_path

Character. Path to the source directory of the R package.

package_name

Character. Name of the package (typically the folder name or actual package name).

Value

A tibble with columns: 'exported_function', 'class', 'function_type', 'function_body', and 'where'.


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


Helper to create maintainer

Description

Helper to create maintainer

Usage

extract_maintainer_info(person_obj)

Arguments

person_obj

- value


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 the Installed Version of a Package

Description

This function retrieves the installed version of a specified R package. If the package is not installed, returns 'NA'.

Usage

extract_package_version(package_name)

Arguments

package_name

A character string specifying the name of the package.

Value

A character string representing the installed package version, or 'NA' if the package is not found.

Examples

## Not run: 
extract_package_version("dplyr")
# 1.1.4

## End(Not run)


Extract Risk Inputs

Description

Compute intermediate risk input values from flattened package data.

Usage

extract_risk_inputs(flat_data)

Arguments

flat_data

Flat package data as returned by normalize_data().

Value

A list of computed values required for risk scoring.


Extract risk thresholds by id

Description

Extract risk thresholds by id

Usage

extract_thresholds_by_id(risk_rule, id_value)

Arguments

risk_rule

- list containing all risk rules

id_value

- character vector containing risk rule choice

Value

list containing specific risk rules


Extract risk thresholds by key

Description

Extract risk thresholds by key

Usage

extract_thresholds_by_key(risk_rule, key_value)

Arguments

risk_rule

- list containing all risk rules

key_value

- character vector containing risk rule choice

Value

list containing specific risk rules


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 All Dependencies for a Package

Description

This function builds and retrieves the full dependency tree for a given R package.

Usage

fetch_all_dependencies(package_name)

Arguments

package_name

A character string specifying the name of the package.

Value

A nested list representing the dependency tree of the package.

Examples

## Not run: 
fetch_all_dependencies("ggplot2")

## 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: 
info <- fetch_bioconductor_package_info("3.14", "GenomicRanges")
print(info)

## 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

Usage

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


Create fine grained traceability matrices

Description

Create fine grained traceability matrices

Usage

fine_grained_tms(tm, pkg_name)

Arguments

tm

- general traceability matrix with no filtered information

pkg_name

- name of the package

Value

- nested list with fine grained tms


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 Fine grained Trace Matrices Section

Description

Generates the Trace Matrices section for the HTML report.

Usage

generate_fg_trace_matrix_section(tm_type, tm_df)

Arguments

tm_type

- type of traceability matrix

tm_df

- 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 = NULL)

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 Popularity Metrics Section

Description

Generates the popularity section for the HTML report.

Usage

generate_pop_metrics_section(assessment_results)

Arguments

assessment_results

- input data


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(total_coverage, file_coverage, tm_df)

Arguments

total_coverage

- total coverage for the package

file_coverage

- file coverage for the package

tm_df

- input data


Assess an R Package traceability matrix from package name and version

Description

This function use 'risk.assessr::create_traceability_matrix' function with only the package name and version

Usage

generate_traceability_matrix(
  package_name,
  version = NA,
  repos = NULL,
  execute_coverage = FALSE
)

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 mirrors

execute_coverage

Logical ('TRUE'/'FALSE'). If 'TRUE', execute test coverage.

Value

The function returns package traceability_matrix If the package cannot be downloaded or installed, an error message is returned.

Examples

## Not run: 
r <- getOption("repos")
# save current repo options  
old <- options(repos = r)
r["CRAN"] = "http://cran.us.r-project.org"
options(repos = r)#' 

results_no_test_covr <- generate_traceability_matrix(
 "here", 
 version = "1.0.1", 
 execute_coverage = FALSE
)

results_test_covr <- generate_traceability_matrix(
 "here", 
 version = "1.0.1", 
 execute_coverage = TRUE
)

# restore user's repo options
options(old)

print(results_no_test_covr)

print(results_test_covr)

## End(Not run)


Extract all S4 methods

Description

Extract all S4 methods

Usage

get_all_s4_methods(generic_name)

Arguments

generic_name

name of function

Value

list with method_strings, generic, and methods


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.

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:

url

The URL of the source package (if available).

version

The specified or latest available package version.

last_version

A list with version, date, and Bioconductor version.

all_versions

A list of all discovered versions with version, date, and Bioconductor version.

bioconductor_version_package

The Bioconductor version matched to the selected version.

archived

A logical value indicating whether the package is archived.

Examples

## Not run: 
release_data <- list(
  list(release = "3.17", date = "October 14, 2005"),
  list(release = "3.18", date = "October 4, 2006"),
  list(release = "3.19", date = "October 8, 2007")
)

get_bioconductor_package_url("GenomicRanges", release_data = release_data)


## End(Not run)

Retrieve GitHub Commits as Weekly Counts (using curl)

Description

This function fetches all commits from a specified GitHub repository using the GitHub API and returns a data frame with weekly commit counts.

Usage

get_commits_since(owner, repo, years = 1)

Arguments

owner

Character. The GitHub username or organization that owns the repository.

repo

Character. The name of the GitHub repository.

years

Numeric. Number of years to look back from today's date (default is 1).

Value

A data frame with four columns:

week_start

Start date of the week (class Date).

year

Year of the commits.

month

Month of the commits.

n_commits

Number of commits during the week.

Examples

## Not run: 
# Get commit counts for the past year
get_commits_since(owner = "tidyverse", repo = "ggplot2")

## 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. If 'NULL', the latest version is assumed.

last_version

A named list with elements version and date, representing the latest available version and its publication date.

all_versions

A list of named lists, each with elements version and date, representing all known versions of the package and their publication dates.

Value

A character string containing the URL to download the package tarball, or "No valid URL found" if the version is not found in the list of available versions.

Examples

## Not run: 
# Example data structure
last_version <- list(version = "1.0.10", date = "2024-01-01")
all_versions <- list(
  list(version = "1.0.0", date = "2023-01-01"),
  list(version = "1.0.10", date = "2024-01-01")
)

# Get the URL for the latest version of "dplyr"
url <- get_cran_package_url("dplyr", NULL, last_version, all_versions)
print(url)

## End(Not run)

Get CRAN Total or Recent Downloads for a Package

Description

Retrieves either all-time total downloads or the total from the last 'n' full months for a given CRAN package.

Usage

get_cran_total_downloads(pkg, months = NULL)

Arguments

pkg

Character string, the name of the CRAN package.

months

Integer. If NULL, returns all-time total; otherwise, returns total from the last 'months' full months (excluding current).

Details

Similar data can be obtained via:

https://cranlogs.r-pkg.org/badges/grand-total/ggplot2 https://cranlogs.r-pkg.org/badges/last-month/ggplot2

Value

An integer: total number of downloads.

Examples

## Not run: 
  get_cran_total_downloads("ggplot2")        # all-time total
  # 160776616

  get_cran_total_downloads("ggplot2", 3)     # last 3 full months
  # 4741707

  get_cran_total_downloads("ggplot2", 12)    # last 12 full months
  # 19878885

## End(Not run)


Get dependencies

Description

Get dependencies

Usage

get_dependencies(pkg_source_path)

Arguments

pkg_source_path

package source path


list all package exports

Description

list all package exports

Usage

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

Examples


dp <- system.file("test-data", "test.package.0001_0.1.0.tar.gz",
package = "risk.assessr")

install_list <- set_up_pkg(dp)

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

get_exports_df <- get_exports(pkg_source_path)


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.

repo

A character string specifying the name of the repository.

A GitHub Personal Access Token (PAT) will be needed for some requests or to help with the rate limit. Use Sys.setenv(GITHUB_TOKEN = "personal_access_token") or store your token in a .Renviron file. The token is passed via the 'Authorization' header only if 'Sys.getenv("GITHUB_TOKEN")' is non-empty.

Details

Repository data is fetched using the GitHub API via 'curl' and 'jsonlite'.

Value

A list containing: - 'created_at': Creation date of the repository. - 'stars': Number of stars. - 'forks': Number of forks. - 'date': Acquisition date (YYYY-MM-DD). - 'recent_commits_count': Number of commits in the last 30 days. - 'open_issues': Number of open issues.

Examples

## Not run: 
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.

Examples

## Not run: 
result <- get_host_package(pkg_name, pkg_version, pkg_source_path)
print(result)

## End(Not run)

Get Internal Package URL

Description

This function retrieves the URL of an internal package on Mirror, its latest version, and a list of all available versions.

Usage

get_internal_package_url(package_name, version = NULL, base_url = NULL)

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 specifying the base URL of the internal package manager.

Value

A list containing: - 'url': A character string of the package URL (or 'NULL' if not found). - 'last_version': A list with 'version' and 'date' of the latest version (or 'NULL'). - 'version': The version used to generate the URL (or 'NULL'). - 'all_versions': A list of all available versions, each as a list with 'version' and 'date'.

Examples

## Not run: 
result <- get_internal_package_url("internalpackage", version = "1.0.1")
print(result)

## End(Not run)


Get License Levels from Thresholds

Description

This internal utility function processes a list of license thresholds and returns a named list of license values grouped by their risk level (e.g., "high", "medium", "low").

Usage

get_license_thresholds(thresholds)

Arguments

thresholds

A list where each element contains a 'level' (character) and 'values' (list of character vectors).

Value

A named list with elements '"high"', '"medium"', and '"low"', each containing a character vector of license names.


Extract Maximum Thresholds for Code Coverage Levels

Description

This internal function retrieves the 'max' values for '"high"','"medium"', and '"low"' levels from a list of code coverage thresholds.

Usage

get_max_thresholds(thresholds)

Arguments

thresholds

A list of threshold objects, each containing a 'level' and 'max' field.

Value

A list with three elements:

high_max

The maximum threshold value for the '"high"' level.

medium_max

The maximum threshold value for the '"medium"' level.

medium_max

The maximum threshold value for the '"low"' level.


Get Bioconductor Package Download Statistics

Description

Downloads and processes monthly download statistics for a Bioconductor package from the Bioconductor package statistics archive. Returns the full history, the total downloads over the last 6 full months (current month excluded), and the all-time total downloads.

Usage

get_package_download_bioconductor(pkg)

Arguments

pkg

Character string. The name of a Bioconductor package (e.g. "GenomicRanges").

Value

A list with three elements:

all_data

A data.frame of the full cleaned dataset with dates and cumulative counts.

total_6_months

Total downloads in the last 6 complete months.

total_download

Total all-time downloads.

Examples

## Not run: 
  result <- get_package_download_bioconductor("bioconductorpackage")
  print(result$total_6_months)
  head(result$all_data)
  
#$all_data
#Date Year Month Nb_of_distinct_IPs Nb_of_downloads Cumulative_downloads
#1   2009-01-01 2009   Jan               3341            7053                 7053
#2   2009-02-01 2009   Feb               3229            6681                13734
#3   2009-03-01 2009   Mar               3753            8021                21755
  
  #$total_6_months
  #[1] 547560
  
  #$total_download
  #[1] 7318550

## End(Not run)


Get CRAN Daily Downloads for a Package

Description

Retrieves daily CRAN download counts over the past years for a given package, including cumulative downloads.

Usage

get_package_download_cran(pkg, years = 1)

Arguments

pkg

Character string, name of the CRAN package.

years

integer, number of past years (default 1) for historical

Value

A data frame with columns: date, count, and cumulative_downloads.

Examples

## Not run: 
  get_package_download_cran("ggplot2")
  # Example output:
  #          date  count cumulative_downloads
  # 1 2025-04-22  78379           20073615
  # 2 2025-04-21  63195           19995236
  # 3 2025-04-20  42119           19932041
  # 4 2025-04-19  40848           19889922
  # 5 2025-04-18  54914           19849074
  # 6 2025-04-17  86273           19794160
  # 7 2025-04-16  80201           19707887

## 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


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 Annual PubMed Article Counts for a Search Term

Description

This function queries the NCBI E-utilities API to retrieve the number of PubMed articles published each year over a specified number of past years for a given search term or package name.

Usage

get_pubmed_by_year(
  package_name,
  years_back = 10,
  api_key = getOption("pubmed.api_key", NULL)
)

Arguments

package_name

A character string representing the search term (e.g., an R package name).

years_back

An integer specifying how many years back to query. Defaults to 10.

api_key

Optional. A character string with an NCBI API key. If not supplied, it will attempt to use the option getOption("pubmed.api_key").

Value

A data frame with two columns:

Year

The publication year (integer).

Count

The number of articles published in that year (integer).

Returns an empty data frame if no valid data is retrieved.

Examples

## Not run: 
get_pubmed_by_year("ggplot2", years_back = 5)

## End(Not run)


Get Total Number of PubMed Articles for a Search Term

Description

This function queries the NCBI E-utilities API to retrieve the total number of PubMed articles that match a given search term or R package name.

Usage

get_pubmed_count(package_name, api_key = getOption("pubmed.api_key", NULL))

Arguments

package_name

A character string representing the search term (e.g., an R package name).

api_key

Optional. A character string with an NCBI API key. If not supplied, it will attempt to use the option getOption("pubmed.api_key").

Value

An integer representing the total number of PubMed articles matching the search term, or NA if the request fails.

Examples

## Not run: 
get_pubmed_count("ggplot2")

## End(Not run)


function to get R6 methods

Description

function to get R6 methods from class

Usage

get_r6_methods_details(class_name)

Arguments

class_name

- function class


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 reverse dependencies

Description

Get reverse dependencies

Usage

get_reverse_dependencies(pkg_source_path)

Arguments

pkg_source_path

package source path


Get Risk Analysis

Description

Compute risk levels for the package metadata.

Usage

get_risk_analysis(data)

Arguments

data

The nested package metadata.

Value

A named list of computed risk levels.

Examples

# Minimal mock input for demonstration
mock_data <- list(
  dependencies_count = 5,
  later_version = 2,
  code_coverage = 0.75,
  last_month_download = 150000,
  license = "MIT",
  reverse_dependencies_count = 10,
  documentation_score = 2,
  cmd_check = 0
)

get_risk_analysis(mock_data)

Get Risk Definition

Description

Load risk definition config from options, JSON file, or fallback to bundled file.

Usage

get_risk_definition()

Value

A list of risk configuration items.

Examples

risk_rule <- get_risk_definition()
print(risk_rule)

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

Usage

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.

Value

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 of a package, including the latest version, by parsing the provided version table and querying the RStudio Package Manager.

Usage

get_versions(table, package_name)

Arguments

table

A list of parsed package data (e.g., from 'parse_html_version()'), where each element contains package details such as 'package_version' and 'date'.

package_name

A character string specifying the name of the package to fetch versions for.

Value

A list with the following elements:

all_versions

A list of named lists, each containing:

version

The version number of the package.

date

The associated publication date as a string.

last_version

A named list containing the latest version of the package with:

version

The latest version number.

date

The publication date of the latest version.

May be NULL if the API call fails.

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"
  )
)

result <- get_versions(table, "here")
print(result)

## End(Not run)


Helper function to replace NULL with "N/A"

Description

Helper function to replace NULL with "N/A"

Usage

handle_null(x)

Arguments

x

- input value


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 - package_installed

Examples

## Not run: 
results <- install_package_local("pkg_source_path")
print(results)

## End(Not run)

Check if a Package is a Base or Recommended R Package

Description

This function determines whether a given package is a base or recommended package using CRAN metadata.

Usage

is_base(pkg)

Arguments

pkg

A character string representing the name of the package.

Value

A logical value: 'TRUE' if the package is a base or recommended package, 'FALSE' otherwise.

Examples

## Not run: 
is_base("stats")     # TRUE
is_base("ggplot2")   # FALSE

## End(Not run)

List badges image URLs from a local README

Description

Scans a local README (Markdown) and returns badge image URLs.

Usage

list_badges(path)

Arguments

path

Character scalar; path to a local README file (e.g., "README.md").

Value

data.frame with badge info

Examples

## Not run: 
tmp <- tempfile(fileext = ".md")
writeLines(c(
  "# MyPkg",
  "![build](build-status.svg)",
  "![cov](coverage.svg)"
), tmp)
out <- list_badges(tmp)
print(out)

## 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

Usage

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


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")

## End(Not run)


Normalize Nested Package Data

Description

Flattens nested package metadata into a flat list for further processing.

Usage

normalize_data(results)

Arguments

results

The nested package metadata (list structure as produced by your package).

Value

A list with flattened package information.


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)
print(release_data)

## 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 Dependencies from a Package DESCRIPTION File

Description

This function extracts and returns the dependencies from the DESCRIPTION file of an R package, focusing on the 'Imports' field.

Usage

parse_dcf_dependencies_version(path)

Arguments

path

A character string specifying the path to the package directory containing the DESCRIPTION file.

Value

A data frame with columns: - 'package': The name of the imported package. - 'type': The type of dependency (e.g., "Imports").

Examples


## Not run: 
parse_dcf_dependencies_version("/path/to/package")

## End(Not run)

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)
## Not run: 
html_content <- parse_package_info("dplyr")
parse_html_version(html_content, "dplyr")

## 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"
parse_package_info("dplyr")


## 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


Description

This function prints a hierarchical representation of a package's dependencies, including version and base status

Usage

print_tree(tree, prefix = "", last = TRUE, show_version = TRUE)

Arguments

tree

A nested list representing the package dependency tree, where each package has a 'version' field and potentially sub-dependencies.

prefix

A character string used for formatting tree branches (default: "").

last

A logical value indicating if the current package is the last in the tree level (default: 'TRUE').

show_version

A logical value indicating whether to display package versions if available (default: 'TRUE').

Value

Prints the dependency tree to the console.

Examples

## Not run: 
db <- list(
  stringr = list(
    version = "1.5.1",
    cli = list(version = "3.6.2", utils = "base"),
    glue = list(version = "1.7.0", methods = "base"),
    lifecycle = list(
      version = "1.0.4",
      cli = list(version = "3.6.2", utils = "base"),
      glue = list(version = "1.7.0", methods = "base"),
      rlang = list(version = "1.1.3", utils = "base")
    ),
    magrittr = list(version = "2.0.3"),
    rlang = list(version = "1.1.3", utils = "base"),
    stringi = list(version = "1.8.3", tools = "base", utils = "base", stats = "base"),
    vctrs = list(
      version = "0.6.5",
      cli = list(version = "3.6.2", utils = "base"),
      glue = list(version = "1.7.0", methods = "base"),
      lifecycle = list(version = "1.0.4"),
      rlang = list(version = "1.1.3", utils = "base")
    )
  )
)
print_tree(db)

## End(Not run)


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


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()

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 expanded from [riskmetric::metric_score.pkg_metric_r_cmd_check()] by including forbidden notes,


Helper to conditionally apply handle_null or abbreviation

Description

Helper to conditionally apply handle_null or abbreviation

Usage

safe_value(x)

Arguments

x

- value


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


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'

mirror server hosted at Truenetwork, Russian Federation.