| Title: | Assessing Package Risk Metrics |
|---|---|
| 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. |
| Authors: | Edward Gillian [cre, aut] (ORCID: <https://orcid.org/0000-0003-2732-5107>), Hugo Bottois [aut] (ORCID: <https://orcid.org/0000-0003-4674-0875>), Paulin Charliquart [aut], Andre Couturier [aut], Sanofi [cph, fnd] |
| Maintainer: | Edward Gillian <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 4.1.0 |
| Built: | 2026-06-11 18:26:26 UTC |
| Source: | https://github.com/cran/risk.assessr |
Use [risk_assess_pkg()] with 'package' instead.
assess_pkg_r_package(package_name, version = NA, repos = getOption("repos"))assess_pkg_r_package(package_name, version = NA, repos = getOption("repos"))
package_name |
Package name. |
version |
Package version. Default 'NA' uses latest. |
repos |
Repository URLs. Default 'getOption("repos")'. |
Assessment results or 'NULL'.
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.
average_issue_close_time( owner, repo, max_pages = 10, per_page = 100, headers = c(Accept = "application/vnd.github.v3+json") )average_issue_close_time( owner, repo, max_pages = 10, per_page = 100, headers = c(Accept = "application/vnd.github.v3+json") )
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. |
Numeric. Average time in hours to close issues, or 'NA' if no closed issues were found.
## Not run: average_issue_close_time("tidyverse", "ggplot2") ## End(Not run)## Not run: average_issue_close_time("tidyverse", "ggplot2") ## End(Not run)
This function returns the reverse dependencies for a given Bioconductor package.
bioconductor_reverse_deps( pkg, which = "Imports", only.bioc = FALSE, version = BiocManager::version(), db = NULL, biocdb = NULL )bioconductor_reverse_deps( pkg, which = "Imports", only.bioc = FALSE, version = BiocManager::version(), db = NULL, biocdb = NULL )
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 |
only.bioc |
Logical. If |
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. |
A named list of reverse dependency package names.
## Not run: # Get reverse Imports dependencies as a list: bioconductor_reverse_deps("limma") # Get multiple categories: bioconductor_reverse_deps("limma", which = c("Depends", "Suggests")) ## End(Not run)## Not run: # Get reverse Imports dependencies as a list: bioconductor_reverse_deps("limma") # Get multiple categories: bioconductor_reverse_deps("limma", which = c("Depends", "Suggests")) ## End(Not run)
This function constructs a nested list representing the dependency tree of a specified R package. The recursion stops at the specified maximum depth level (default: 3) or until a base package is reached.
build_dependency_tree( package_name, level = 1, get_license = FALSE, max_level = 3 )build_dependency_tree( package_name, level = 1, get_license = FALSE, max_level = 3 )
package_name |
A character string specifying the name of the package. |
level |
An integer indicating the current recursion depth (default: 1). |
get_license |
A logical value indicating whether to extract and include license information from DESCRIPTION files (default: 'FALSE'). |
max_level |
An integer specifying the maximum depth level for dependency recursion (default: 3). Set to a higher value to explore deeper dependency layers. |
A nested list representing the dependency tree, where base packages are marked as "base". If 'get_license' is 'TRUE', each package entry in the tree includes a 'license' field containing that specific package's license (extracted from its DESCRIPTION file). Each package's license is independent - the license of a parent package does not imply the licenses of its dependencies.
## Not run: build_dependency_tree("ggplot2") build_dependency_tree("ggplot2", get_license = TRUE) build_dependency_tree("ggplot2", max_level = 5) # Deeper dependency exploration ## End(Not run)## Not run: build_dependency_tree("ggplot2") build_dependency_tree("ggplot2", get_license = TRUE) build_dependency_tree("ggplot2", max_level = 5) # Deeper dependency exploration ## End(Not run)
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.
check_and_fetch_cran_package(package_name, package_version = NULL)check_and_fetch_cran_package(package_name, package_version = NULL)
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'. |
A list with one of the following structures:
Character string; the URL to download the package tarball.
A named list with version and date for the latest available version.
Character string; the requested version (or NULL if not specified).
A list of named lists, each with version and date, representing all available versions.
## 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)## 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)
This function checks if a given package is available on CRAN.
check_cran_package(package_name)check_cran_package(package_name)
package_name |
A character string specifying the name of the package to check. |
A logical value: 'TRUE' if the package exists on CRAN, 'FALSE' otherwise.
## Not run: # Check if the package "ggplot2" exists on CRAN check_cran_package("ggplot2") ## End(Not run)## Not run: # Check if the package "ggplot2" exists on CRAN check_cran_package("ggplot2") ## End(Not run)
Counts the total number of commits from the last 'months' months using a data frame with weekly commit data (column 'week_start').
count_commits_last_months(df, months = 1, today = Sys.Date())count_commits_last_months(df, months = 1, today = Sys.Date())
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() |
Integer. Total number of commits in the time window.
## Not run: df <- get_commits_since("tidyverse", "ggplot2", years = 1) count_commits_last_months(df, months = 3) ## End(Not run)## Not run: df <- get_commits_since("tidyverse", "ggplot2", years = 1) count_commits_last_months(df, months = 3) ## End(Not run)
Downloads and caches the current list of packages available on CRAN.
cran_packages(cache = TRUE)cran_packages(cache = TRUE)
cache |
Logical. If |
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.
A matrix of package metadata similar to the output of utils::available.packages(),
with package names as row names.
## Not run: # Downloads packages.rds from CRAN (needs network). pkgs <- cran_packages() head(rownames(pkgs)) ## End(Not run)## Not run: # Downloads packages.rds from CRAN (needs network). pkgs <- cran_packages() head(rownames(pkgs)) ## End(Not run)
This function finds the reverse dependencies of a CRAN package, i.e., packages that depend on the specified package.
cran_revdep( pkg, dependencies = c("Depends", "Imports", "Suggests", "LinkingTo"), recursive = FALSE, ignore = NULL, installed = NULL )cran_revdep( pkg, dependencies = c("Depends", "Imports", "Suggests", "LinkingTo"), recursive = FALSE, ignore = NULL, installed = NULL )
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. |
deps - A sorted character vector of package names that depend on the specified package.
## Not run: cran_revdep("ggplot2") ## End(Not run)## Not run: cran_revdep("ggplot2") ## End(Not run)
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.
create_traceability_matrix( pkg_name, pkg_source_path, func_covr = NULL, verbose = FALSE, execute_coverage = TRUE )create_traceability_matrix( pkg_name, pkg_source_path, func_covr = NULL, verbose = FALSE, execute_coverage = TRUE )
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. |
a nested list with fine grained traceability matrices
## 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 package_installed <- TRUE covr_list <- test.assessr::get_package_coverage( pkg_source_path, package_installed ) # 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)## 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 package_installed <- TRUE covr_list <- test.assessr::get_package_coverage( pkg_source_path, package_installed ) # 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)
This function identifies packages that depend on the specified packages, considering various types of dependencies (e.g., strong, most, all).
dependsOnPkgs( pkgs, dependencies = "most", recursive = TRUE, lib.loc = NULL, installed = NULL )dependsOnPkgs( pkgs, dependencies = "most", recursive = TRUE, lib.loc = NULL, installed = NULL )
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. . |
A character vector of package names that depend on the specified packages.
## Not run: installed <- cran_packages() dependsOnPkgs("here", installed = installed) ## End(Not run)## Not run: installed <- cran_packages() dependsOnPkgs("here", installed = installed) ## End(Not run)
This function identifies duplicate version packages and reports conflicts.
detect_version_conflicts(pkg_list)detect_version_conflicts(pkg_list)
pkg_list |
A nested list structure from fetch_all_dependencies function |
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.
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)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)
Downloads a package from a repository, extracts it, and parses dependencies from the DESCRIPTION file.
download_and_parse_dependencies( package_name, version = NA, get_license = FALSE )download_and_parse_dependencies( package_name, version = NA, get_license = FALSE )
package_name |
Name of the package to download. |
version |
Package version to download (default: 'NA' for latest). |
get_license |
Whether to extract license information (default: 'FALSE'). |
The 'license' field refers only to the package specified by 'package_name', not its dependencies. Use 'build_dependency_tree()' or 'fetch_all_dependencies()' with 'get_license = TRUE' for full license information.
When 'get_license = FALSE', a data frame with columns 'package', 'type', and 'parent_package'. When 'get_license = TRUE', a list with: - 'dependencies': Data frame of direct dependencies. - 'license': License of the specified package only (not dependencies). Returns 'NA' if not found.
## Not run: download_and_parse_dependencies("dplyr") download_and_parse_dependencies("dplyr", get_license = TRUE) ## End(Not run)## Not run: download_and_parse_dependencies("dplyr") download_and_parse_dependencies("dplyr", get_license = TRUE) ## End(Not run)
This function retrieves the installed version of a specified R package. If the package is not installed, returns 'NA'.
extract_package_version(package_name)extract_package_version(package_name)
package_name |
A character string specifying the name of the package. |
A character string representing the installed package version, or 'NA' if the package is not found.
## Not run: extract_package_version("dplyr") # 1.1.4 ## End(Not run)## Not run: extract_package_version("dplyr") # 1.1.4 ## End(Not run)
Extract risk thresholds by id
extract_thresholds_by_id(risk_rule, id_value)extract_thresholds_by_id(risk_rule, id_value)
risk_rule |
- list containing all risk rules |
id_value |
- character vector containing risk rule choice |
list containing specific risk rules
Extract risk thresholds by key
extract_thresholds_by_key(risk_rule, key_value)extract_thresholds_by_key(risk_rule, key_value)
risk_rule |
- list containing all risk rules |
key_value |
- character vector containing risk rule choice |
list containing specific risk rules
This function extracts the version number from a package source file name based on the package name and expected file pattern.
extract_version(path, package_name)extract_version(path, package_name)
path |
A character string specifying the file path or URL. |
package_name |
A character string specifying the name of the package. |
A character string representing the extracted version number, or 'NULL' if no match is found.
## 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)## 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)
This function builds and retrieves the full dependency tree for a given R package.
fetch_all_dependencies(package_name, get_license = FALSE, max_level = 3)fetch_all_dependencies(package_name, get_license = FALSE, max_level = 3)
package_name |
A character string specifying the name of the package. |
get_license |
A logical value indicating whether to extract and include license information from DESCRIPTION files (default: 'FALSE'). |
max_level |
An integer specifying the maximum depth level for dependency recursion (default: 3). Set to a higher value to explore deeper dependency layers. |
A nested list representing the dependency tree of the package. If 'get_license' is 'TRUE', each package in the tree (including the root package and all dependencies) will have a ‘license' field containing that package’s license extracted from its DESCRIPTION file.
## Not run: fetch_all_dependencies("ggplot2") fetch_all_dependencies("ggplot2", get_license = TRUE) fetch_all_dependencies("ggplot2", max_level = 5) # Deeper dependency exploration ## End(Not run)## Not run: fetch_all_dependencies("ggplot2") fetch_all_dependencies("ggplot2", get_license = TRUE) fetch_all_dependencies("ggplot2", max_level = 5) # Deeper dependency exploration ## End(Not run)
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.
fetch_bioconductor_package_info(bioconductor_version, package_name)fetch_bioconductor_package_info(bioconductor_version, package_name)
bioconductor_version |
A character string specifying the Bioconductor version (e.g., "3.14"). |
package_name |
A character string specifying the name of the package. |
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.
## Not run: info <- fetch_bioconductor_package_info("3.14", "GenomicRanges") print(info) ## End(Not run)## Not run: info <- fetch_bioconductor_package_info("3.14", "GenomicRanges") print(info) ## End(Not run)
This function retrieves the Bioconductor release announcements page and returns its HTML content for further processing.
fetch_bioconductor_releases()fetch_bioconductor_releases()
An XML document from bioconductor version page.
## Not run: html_content <- fetch_bioconductor_releases() ## End(Not run)## Not run: html_content <- fetch_bioconductor_releases() ## End(Not run)
Generates an HTML report for the package assessment results using rmarkdown.
generate_html_report(assessment_results, output_dir = NULL)generate_html_report(assessment_results, output_dir = NULL)
assessment_results |
List containing the results from risk_assess_pkg function. |
output_dir |
Character string indicating the directory where the report will be saved. |
Path to the generated HTML report.
## Not run: assessment_results <- risk_assess_pkg() generate_html_report(assessment_results, output_dir = "path/to/save/report") ## End(Not run)## Not run: assessment_results <- risk_assess_pkg() generate_html_report(assessment_results, output_dir = "path/to/save/report") ## End(Not run)
This function use 'risk.assessr::create_traceability_matrix' function with only the package name and version
generate_traceability_matrix( package_name, version = NA, repos = getOption("repos"), execute_coverage = FALSE )generate_traceability_matrix( package_name, version = NA, repos = getOption("repos"), execute_coverage = FALSE )
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 getOption("repos") |
execute_coverage |
Logical ('TRUE'/'FALSE'). If 'TRUE', execute test coverage. |
The function returns package traceability_matrix If the package cannot be downloaded or installed, an error message is returned.
## Not run: 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 ) print(results_no_test_covr) print(results_test_covr) ## End(Not run)## Not run: 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 ) print(results_no_test_covr) print(results_test_covr) ## End(Not run)
This function fetches the source package URL for a given Bioconductor package. If no version is specified, it retrieves the latest available version.
get_bioconductor_package_url( package_name, package_version = NULL, release_data )get_bioconductor_package_url( package_name, package_version = NULL, release_data )
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. |
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. |
## 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)## 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)
This function fetches all commits from a specified GitHub repository using the GitHub API and returns a data frame with weekly commit counts.
get_commits_since(owner, repo, years = 1)get_commits_since(owner, repo, years = 1)
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). |
A data frame with four columns:
Start date of the week (class Date).
Year of the commits.
Month of the commits.
Number of commits during the week.
## Not run: # Get commit counts for the past year get_commits_since(owner = "tidyverse", repo = "ggplot2") ## End(Not run)## Not run: # Get commit counts for the past year get_commits_since(owner = "tidyverse", repo = "ggplot2") ## End(Not run)
This function constructs the CRAN package URL for a specified package and version.
get_cran_package_url(package_name, version, last_version, all_versions)get_cran_package_url(package_name, version, last_version, all_versions)
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. |
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.
## 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)## 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)
Retrieves either all-time total downloads or the total from the last 'n' full months for a given CRAN package.
get_cran_total_downloads(pkg, months = NULL)get_cran_total_downloads(pkg, months = NULL)
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). |
Similar data can be obtained via:
https://cranlogs.r-pkg.org/badges/grand-total/ggplot2 https://cranlogs.r-pkg.org/badges/last-month/ggplot2
An integer: total number of downloads.
## 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)## 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)
list all package exports
get_exports(pkg_source_path)get_exports(pkg_source_path)
pkg_source_path |
a file path pointing to an unpacked/untarred package directory |
data.frame, with one column 'exported_function', that can be passed to all downstream map_* helpers
## Not run: tmpdir <- tempdir() # Locate the package source tarball bundled with risk.assessr dp <- system.file("test-data", "test.package.0001_0.1.0.tar.gz", package = "risk.assessr") # Extract the source package into the temporary directory utils::untar(dp, exdir = tmpdir) # Find the extracted package directory (it should contain DESCRIPTION) pkg_dirs <- list.dirs(tmpdir, full.names = TRUE, recursive = FALSE) desc_dir <- pkg_dirs[file.exists(file.path(pkg_dirs, "DESCRIPTION"))] stopifnot(length(desc_dir) == 1L) pkg_source_path <- desc_dir # Now operate on the *source* (no installation) exports_df <- get_exports(pkg_source_path) # Optional: inspect result (kept simple for examples) head(exports_df) # Clean up the extracted sources unlink(pkg_source_path, recursive = TRUE, force = TRUE) ## End(Not run)## Not run: tmpdir <- tempdir() # Locate the package source tarball bundled with risk.assessr dp <- system.file("test-data", "test.package.0001_0.1.0.tar.gz", package = "risk.assessr") # Extract the source package into the temporary directory utils::untar(dp, exdir = tmpdir) # Find the extracted package directory (it should contain DESCRIPTION) pkg_dirs <- list.dirs(tmpdir, full.names = TRUE, recursive = FALSE) desc_dir <- pkg_dirs[file.exists(file.path(pkg_dirs, "DESCRIPTION"))] stopifnot(length(desc_dir) == 1L) pkg_source_path <- desc_dir # Now operate on the *source* (no installation) exports_df <- get_exports(pkg_source_path) # Optional: inspect result (kept simple for examples) head(exports_df) # Clean up the extracted sources unlink(pkg_source_path, recursive = TRUE, force = TRUE) ## End(Not run)
This function retrieves metadata about a GitHub repository, including creation date, stars, forks, and the number of recent commits within the last 30 days.
get_github_data(owner, repo)get_github_data(owner, repo)
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. |
Repository data is fetched using the GitHub API via 'curl' and 'jsonlite'.
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.
## Not run: result <- get_github_data("tidyverse", "ggplot2") print(result) ## End(Not run)## Not run: result <- get_github_data("tidyverse", "ggplot2") print(result) ## End(Not run)
This function retrieves hosting links for an R package from various sources such as GitHub, CRAN, internal repositories, or Bioconductor.
get_host_package(pkg_name, pkg_version, pkg_source_path)get_host_package(pkg_name, pkg_version, pkg_source_path)
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. |
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'
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.
## Not run: result <- get_host_package(pkg_name, pkg_version, pkg_source_path) print(result) ## End(Not run)## Not run: result <- get_host_package(pkg_name, pkg_version, pkg_source_path) print(result) ## End(Not run)
This function retrieves the URL of an internal package on Sanofi Mirror, its latest version, and a list of all available versions.
get_internal_package_url(package_name, version = NULL, base_url = NULL)get_internal_package_url(package_name, version = NULL, base_url = NULL)
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. |
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'.
## Not run: result <- get_internal_package_url("internalpackage", version = "1.0.1") print(result) ## End(Not run)## Not run: result <- get_internal_package_url("internalpackage", version = "1.0.1") print(result) ## End(Not run)
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.
get_package_download_bioconductor(pkg)get_package_download_bioconductor(pkg)
pkg |
Character string. The name of a Bioconductor package (e.g. "GenomicRanges"). |
A list with three elements:
A data.frame of the full cleaned dataset with dates and cumulative counts.
Total downloads in the last 6 complete months.
Total all-time downloads.
## 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)## 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)
Retrieves daily CRAN download counts over the past years for a given package, including cumulative downloads.
get_package_download_cran(pkg, years = 1)get_package_download_cran(pkg, years = 1)
pkg |
Character string, name of the CRAN package. |
years |
integer, number of past years (default 1) for historical |
A data frame with columns: date, count, and cumulative_downloads.
## 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)## 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)
Downloads the source tarball (.tar.gz) for a specified R package from CRAN, Bioconductor, or an internal repository fallback.
get_package_tarfile(package_name, version = NULL, repos = getOption("repos"))get_package_tarfile(package_name, version = NULL, repos = getOption("repos"))
package_name |
Character string specifying the name of the package to download. |
version |
Optional character string specifying the version of the package. If NULL (default), the latest available version will be downloaded. |
repos |
Optional character vector of repository URLs to use. If NULL (default), the current repositories set in options() will be used. |
Character string with the path to the downloaded tarball file, or NULL if the download was unsuccessful.
## Not run: # Download the latest version of dplyr tarball_path <- get_package_tarfile("dplyr") # Download a specific version tarball_path <- get_package_tarfile("dplyr", version = "1.0.0") # Use a specific repository tarball_path <- get_package_tarfile("dplyr", repos = "https://cloud.r-project.org") ## End(Not run)## Not run: # Download the latest version of dplyr tarball_path <- get_package_tarfile("dplyr") # Download a specific version tarball_path <- get_package_tarfile("dplyr", version = "1.0.0") # Use a specific repository tarball_path <- get_package_tarfile("dplyr", repos = "https://cloud.r-project.org") ## End(Not run)
get package name for display
get_pkg_name(input_string)get_pkg_name(input_string)
input_string |
- string containing package name |
pkg_disp - package name for display
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)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)
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.
get_pubmed_by_year( package_name, years_back = 10, api_key = getOption("pubmed.api_key", NULL) )get_pubmed_by_year( package_name, years_back = 10, api_key = getOption("pubmed.api_key", NULL) )
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 |
A data frame with two columns:
The publication year (integer).
The number of articles published in that year (integer).
Returns an empty data frame if no valid data is retrieved.
## Not run: get_pubmed_by_year("ggplot2", years_back = 5) ## End(Not run)## Not run: get_pubmed_by_year("ggplot2", years_back = 5) ## End(Not run)
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.
get_pubmed_count(package_name, api_key = getOption("pubmed.api_key", NULL))get_pubmed_count(package_name, api_key = getOption("pubmed.api_key", NULL))
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 |
An integer representing the total number of PubMed articles matching the search term,
or NA if the request fails.
## Not run: get_pubmed_count("ggplot2") ## End(Not run)## Not run: get_pubmed_count("ggplot2") ## End(Not run)
Compute risk levels for the package metadata.
get_risk_analysis(data)get_risk_analysis(data)
data |
The nested package metadata. |
A named list of computed risk levels.
# 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, has_examples = list( data = data.frame( function_name = "somefunction", documentation_name = "No documentation found", documentation_location = 0, example = "no Rd file", stringsAsFactors = FALSE ), example_score = 0.20 ), has_docs = list( data = data.frame( function_name = "somefunction", stringsAsFactors = FALSE ), has_docs_score = 0.30 ), cmd_check = 0 ) get_risk_analysis(mock_data)# 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, has_examples = list( data = data.frame( function_name = "somefunction", documentation_name = "No documentation found", documentation_location = 0, example = "no Rd file", stringsAsFactors = FALSE ), example_score = 0.20 ), has_docs = list( data = data.frame( function_name = "somefunction", stringsAsFactors = FALSE ), has_docs_score = 0.30 ), cmd_check = 0 ) get_risk_analysis(mock_data)
Load risk definition config from options, JSON file, or fallback to bundled file.
get_risk_definition()get_risk_definition()
A list of risk configuration items.
risk_rule <- get_risk_definition() print(risk_rule)risk_rule <- get_risk_definition() print(risk_rule)
This function extracts the version information of imported and suggested packages for a given package from the current R session.
get_session_dependencies(deps_list)get_session_dependencies(deps_list)
deps_list |
A data frame containing the dependency information of the package (provided by calc_dependencies function) |
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 |
deps_list <- data.frame( package = c("dplyr", "ggplot2", "testthat", "knitr"), type = c("Imports", "Imports", "Suggests", "Suggests") ) get_session_dependencies(deps_list)deps_list <- data.frame( package = c("dplyr", "ggplot2", "testthat", "knitr"), type = c("Imports", "Imports", "Suggests", "Suggests") ) get_session_dependencies(deps_list)
This function gets exported functions for all packages in the Suggests section of the target package's DESCRIPTION file
get_suggested_exp_funcs(data)get_suggested_exp_funcs(data)
data |
- all packages listed in the DESCRIPTION file |
- data with package names and exported functions
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.
get_versions(table, package_name)get_versions(table, package_name)
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. |
A list with the following elements:
A list of named lists, each containing:
The version number of the package.
The associated publication date as a string.
A named list containing the latest version of the package with:
The latest version number.
The publication date of the latest version.
May be NULL if the API call fails.
## 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)## 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)
Install package locally
install_package_local(pkg_source_path)install_package_local(pkg_source_path)
pkg_source_path |
- source path for install local |
logical - package_installed
## Not run: results <- install_package_local("pkg_source_path") print(results) ## End(Not run)## Not run: results <- install_package_local("pkg_source_path") print(results) ## End(Not run)
This function determines whether a given package is a base or recommended package using CRAN metadata.
is_base(pkg)is_base(pkg)
pkg |
A character string representing the name of the package. |
A logical value: 'TRUE' if the package is a base or recommended package, 'FALSE' otherwise.
## Not run: is_base("stats") # TRUE is_base("ggplot2") # FALSE ## End(Not run)## Not run: is_base("stats") # TRUE is_base("ggplot2") # FALSE ## End(Not run)
Scans a local README (Markdown) and returns badge image URLs.
list_badges(path)list_badges(path)
path |
Character scalar; path to a local README file (e.g., "README.md"). |
data.frame with badge info
## Not run: tmp <- tempfile(fileext = ".md") writeLines(c( "# MyPkg", "", "" ), tmp) out <- list_badges(tmp) print(out) ## End(Not run)## Not run: tmp <- tempfile(fileext = ".md") writeLines(c( "# MyPkg", "", "" ), tmp) out <- list_badges(tmp) print(out) ## End(Not run)
This function recreate a '.tar.gz' R package file after modifying its 'DESCRIPTION' file by appending Config/build/clean-inst-doc: false parameter.
modify_description_file(tar_file)modify_description_file(tar_file)
tar_file |
A string representing the path to the '.tar.gz' file that contains the R package. |
A string containing the path to the newly created modified '.tar.gz' file, or the original 'tar_file' path unchanged if modification was unnecessary or failed.
## Not run: modified_tar <- modify_description_file("path/to/mypackage.tar.gz") ## End(Not run)## Not run: modified_tar <- modify_description_file("path/to/mypackage.tar.gz") ## End(Not run)
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.
parse_bioconductor_releases(html_content)parse_bioconductor_releases(html_content)
html_content |
The parsed HTML document from 'fetch_bioconductor_releases'. |
A list of lists containing Bioconductor release details: release version, date, number of software packages, and corresponding R version.
## Not run: html_content <- fetch_bioconductor_releases() release_data <- parse_bioconductor_releases(html_content) print(release_data) ## End(Not run)## Not run: html_content <- fetch_bioconductor_releases() release_data <- parse_bioconductor_releases(html_content) print(release_data) ## End(Not run)
This function retrieves the package archive information from the CRAN Archive.
parse_package_info(name)parse_package_info(name)
name |
A character string specifying the name of the package to fetch information for. |
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.
## Not run: # Fetch package archive information for "dplyr" parse_package_info("dplyr") ## End(Not run)## Not run: # Fetch package archive information for "dplyr" parse_package_info("dplyr") ## End(Not run)
This function prints a hierarchical representation of a package's dependencies, including version and base status
print_tree(tree, prefix = "", last = TRUE, show_version = TRUE)print_tree(tree, prefix = "", last = TRUE, show_version = TRUE)
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'). |
Prints the dependency tree to the console.
## 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)## 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)
Assess an R package for risk metrics. Use exactly one of: * 'path' – path to a local .tar.gz archive, or * 'package' – package name to fetch (optionally with 'version'), or * neither – opens an interactive file chooser.
risk_assess_pkg( path = NULL, package = NULL, version = NA, repos = getOption("repos") )risk_assess_pkg( path = NULL, package = NULL, version = NA, repos = getOption("repos") )
path |
Path to a local .tar.gz package archive. Use only when not providing 'package'. |
package |
Package name to fetch from CRAN, Bioconductor, or internal repos. Use only when not providing 'path'. |
version |
(optional) Package version when using 'package'. Default 'NA' uses the latest available. |
repos |
Repository URLs when fetching by 'package'. Default is 'getOption("repos")'. |
List containing results (metrics, covr, trace matrix, R CMD check), or 'NULL' if the package cannot be assessed.
## Not run: # Local package (path or file chooser) results <- risk_assess_pkg() results <- risk_assess_pkg(path = "path/to/package.tar.gz") # Package by name from repositories results <- risk_assess_pkg(package = "here") results <- risk_assess_pkg(package = "here", version = "1.0.1") results <- risk_assess_pkg(package = "here", repos = "https://cloud.r-project.org") ## End(Not run)## Not run: # Local package (path or file chooser) results <- risk_assess_pkg() results <- risk_assess_pkg(path = "path/to/package.tar.gz") # Package by name from repositories results <- risk_assess_pkg(package = "here") results <- risk_assess_pkg(package = "here", version = "1.0.1") results <- risk_assess_pkg(package = "here", repos = "https://cloud.r-project.org") ## End(Not run)
This function processes 'renv.lock' and 'pak.lock' files to produce risk metric data
risk_assess_pkg_lock_files(input_data)risk_assess_pkg_lock_files(input_data)
input_data |
- path to a lock file |
assessment_results - nested list containing risk metric data
## Not run: input_data <- ("path/to/mypak.lock") pak_results <- risk_assess_pkg_lock_files(input_data) print(pak_results) ## End(Not run)## Not run: input_data <- ("path/to/mypak.lock") pak_results <- risk_assess_pkg_lock_files(input_data) print(pak_results) ## End(Not run)
Creates information on package installation
set_up_pkg(package_path, check_type = "1")set_up_pkg(package_path, check_type = "1")
package_path |
Path to the package tarball (.tar.gz). |
check_type |
Type of R CMD check: "1" for basic, "2" for CRAN-like. |
list with local package install
## Not run: set_up_pkg("path/to/tarball") ## End(Not run)## Not run: set_up_pkg("path/to/tarball") ## End(Not run)
Renders the package risk assessment report ('summary.Rmd') to a chosen format and writes it to disk. The output file path can be inferred or explicitly set. You can specify the output format directly via 'output_format' or let it be inferred from the extension of 'output_file'. If 'output_dir' is not provided, the current working directory is used.
write_summary_report( results, output_file = NULL, output_format = NULL, output_dir = NULL )write_summary_report( results, output_file = NULL, output_format = NULL, output_dir = NULL )
results |
A results object containing the risk assessment results. It is expected to include 'results$results$pkg_name' and 'results$results$pkg_version', which are used to construct default file names and report parameters. |
output_file |
'character(1)' or 'NULL'. The output file path **or** a directory. - If 'NULL', a default name is generated: '"summary_report_<pkg_name>_<pkg_version>.html"' in 'output_dir'. - If it is a directory, the default name is composed inside it. - If it is a relative path, it is resolved against 'output_dir'. |
output_format |
'character(1)' or 'NULL'. Explicit output format to render: one of '"html"' or '"md"' (case-insensitive; do **not** include a leading dot). If 'NULL', the format is inferred from the extension of 'output_file'. Unknown values trigger a warning and default to HTML. |
output_dir |
'character(1)' or 'NULL'. Base directory used when 'output_file' is 'NULL' or a relative path. If 'NULL', defaults to the current working directory ('getwd()'), with an informational message. |
The function calls [rmarkdown::render()] on an internal template: 'system.file("report_templates", "summary.Rmd", package = "risk.assessr")'.
The format mapping is: - '"html"' -> [rmarkdown::html_document()] - '"md"' -> [rmarkdown::md_document()]
If 'output_format' is provided, it takes precedence for rendering even if 'output_file' has a different extension; in that case the filename is adjusted to match the format. If 'output_format' is not provided, the function infers the format from ‘output_file'’s extension. For unknown extensions, it warns and rewrites the extension to '.html'.
(Invisibly) the absolute path to the written report file.
- If 'output_dir' is 'NULL', it defaults to 'getwd()' and a message is printed. - If 'output_file' is 'NULL', a file name is auto-generated as '"summary_report_<pkg>_<version>.html"' inside 'output_dir'. - If 'output_file' points to an existing directory (or ends with a path separator), a file name is composed inside that directory as '"summary_report_<pkg>_<version>.html"'. - If 'output_file' is a relative path, it is resolved against 'output_dir'. - If 'output_format' is provided, it determines the render format (and the 'output_file' name is adjusted to match the format). - If 'output_format' is not provided, the render format is inferred from the extension of 'output_file'. Unknown extensions trigger a warning and the extension is changed to '.html'.
## Not run: # generate assessment_results results <- risk_assess_pkg() # Basic usage: auto-name in the working directory (HTML) write_summary_report(results) # Specify output directory (auto-name inside that directory) write_summary_report(results, output_dir = "artifacts") # Provide an explicit filename (relative to output_dir) write_summary_report(results, output_file = "reports/summary.html") # Provide a directory as output_file: auto-name inside that directory write_summary_report(results, output_file = "reports/") # Render to Markdown explicitly write_summary_report(results, output_format = "md") # Let the extension drive the format (md) write_summary_report(results, output_file = "reports/summary.md") # Case-insensitive formats work; avoid leading dots (".md" is not valid) write_summary_report(results, output_format = "MD") ## End(Not run)## Not run: # generate assessment_results results <- risk_assess_pkg() # Basic usage: auto-name in the working directory (HTML) write_summary_report(results) # Specify output directory (auto-name inside that directory) write_summary_report(results, output_dir = "artifacts") # Provide an explicit filename (relative to output_dir) write_summary_report(results, output_file = "reports/summary.html") # Provide a directory as output_file: auto-name inside that directory write_summary_report(results, output_file = "reports/") # Render to Markdown explicitly write_summary_report(results, output_format = "md") # Let the extension drive the format (md) write_summary_report(results, output_file = "reports/summary.md") # Case-insensitive formats work; avoid leading dots (".md" is not valid) write_summary_report(results, output_format = "MD") ## End(Not run)