| Type: | Package |
| Title: | Package Version Comparison |
| Version: | 1.0.0 |
| Description: | Compares two versions of a package release and reports what changed between them including 'DESCRIPTION' metadata and exported functions in dependencies. This is useful for preparing release notes and migration guides, and for assessing the risk of upgrading a dependency. |
| License: | GPL (≥ 3) |
| BugReports: | https://github.com/Sanofi-Public/whatsnew/issues |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.1.0) |
| Imports: | remotes, dplyr, purrr, magrittr, rlang, utils, risk.assessr (≥ 3.0.0), igraph, pkgnet |
| Suggests: | knitr, rmarkdown, mockery, withr, testthat (≥ 3.0.0), stringr, here, jsonlite |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.0.0 |
| RoxygenNote: | 7.3.2 |
| NeedsCompilation: | no |
| Packaged: | 2026-11-10 13:25:31 UTC; I0555262 |
| Author: | Hugo Bottois |
| Maintainer: | Hugo Bottois <hugo.bottois@sanofi.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-12-01 15:20:02 UTC |
Compare Two Versions of a Package
Description
This function retrieves information for two versions of an R package, compares their dependencies, exported functions, and test metrics, and returns the differences as a structured R list.
Usage
compare(package_name, package_version_new, package_version_old)
Arguments
package_name |
Character string with the package name (e.g. '"dplyr"'). |
package_version_new |
Character string with the newer version number. |
package_version_old |
Character string with the older version number. |
Value
A list containing:
- package
Package name
- version_new
Newer version number
- version_old
Older version number
- dependencies_diff
Comparison of dependencies
- functions_diff
Comparison of functions
- test_m
Comparison of test metrics
Examples
if (requireNamespace("dplyr", quietly = TRUE)) {
pkg_diff <- compare("dplyr", "1.1.4", "1.0.9")
str(pkg_diff)
}
Compare one column across two data frames by key
Description
Inner-joins two data frames on key column(s) and compares a single column between them. Returns the keys, the two suffixed columns, and a logical 'different' flag with NA-aware rules.
Usage
compare_column(
df1,
df2,
key,
param_col,
name1 = "tm_list_1_tm",
name2 = "tm_list_2_tm",
only_diff = TRUE
)
Arguments
df1 |
A data frame. |
df2 |
A data frame. |
key |
Character vector of join key(s), passed to 'dplyr::inner_join(by = key)'. |
param_col |
String. Base name of the column to compare (without suffixes). |
name1, name2 |
Suffixes for the compared columns from 'df1' and 'df2'. Defaults: '"tm_list_1_tm"' and '"tm_list_2_tm"'. |
only_diff |
Logical. If 'TRUE' (default), keep only rows where values differ. If 'FALSE', return all joined rows with a 'different' flag. |
Value
A tibble with the key column(s), '<param_col>_<name1>', '<param_col>_<name2>', and 'different' (logical). If 'only_diff = TRUE', only rows with 'different = TRUE' are kept.
Compare Two DESCRIPTION Dependency Strings
Description
Identifies added, removed, and modified dependencies between two versions.
Usage
compare_dep_fields(dep_new, dep_old)
Arguments
dep_new |
A dependency string from the newer DESCRIPTION. |
dep_old |
A dependency string from the older DESCRIPTION. |
Value
A list with 'added', 'removed', and 'modified' components.
Compare Two Versions of an R Package
Description
Downloads both versions of a package and compares dependencies and function definitions.
Usage
compare_dependencies(info_new, info_old)
Arguments
info_new |
The newer version. |
info_old |
The older version. |
Value
A list summarizing added/removed/modified dependencies and functions.
Compare Exported Functions Between Two Versions
Description
Compare Exported Functions Between Two Versions
Usage
compare_funcs(new_funcs, old_funcs)
Arguments
new_funcs |
Named list: names are function names, values are lists of formals. |
old_funcs |
Named list: same as above. |
Value
A list with 'added', 'removed', and 'modified' function names.
Compare Traceability Matrices (TM) Between Two Package Versions
Description
This function compares the traceability matrices (TMs) generated for two versions of an R package. It identifies differences in selected fields (such as function type, body, and description) across versions.
Usage
compare_tm(
package_name,
version_new,
version_old,
fields = c("function_type", "function_body", "description")
)
Arguments
package_name |
Character string, the name of the package to compare. |
version_new |
Character string, the newer version of the package. |
version_old |
Character string, the older version of the package. |
fields |
Character vector of TM fields to compare. Defaults to 'c("function_type", "function_body", "description")'. |
Details
The function leverages 'risk.assessr::generate_traceability_matrix()' to extract TM data for each version, then compares them using 'compare_column()' and outputs a tidy data frame summarizing differences.
Value
A tibble with columns:
- exported_function
Function name being compared
- field
The TM field that differs
- value_<package>_<new_version>
Value from the newer version
- value_<package>_<old_version>
Value from the older version
Examples
# Compare traceability matrices for two versions of a package
if (requireNamespace("dplyr", quietly = TRUE)) {
diff_tm <- compare_tm("dplyr", "1.1.4", "1.0.8")
head(diff_tm)
}
Extract Package Names and Versions from DESCRIPTION Dependency Fields
Description
Parses a string of dependencies (e.g. from 'Imports' or 'Depends') into a data frame with package names and versions.
Usage
extract_versions(dep_string)
Arguments
dep_string |
A string from a DESCRIPTION dependency field (e.g., 'Imports'). |
Value
A data frame with columns 'pkg' and 'version'.
Format function argument formals as strings
Description
Helper that formats a list of function arguments and their default values.
Usage
format_formals(formals)
Arguments
formals |
A named list of function arguments. Each element is either 'NULL' (no default) or a string representing the default value. |
Value
A character vector of formatted arguments.
Build a Nested Function Call Tree
Description
Builds a nested list representation of a package’s **function call tree** using [pkgnet::FunctionReporter]. This is usually consumed by [print_function_tree()] for pretty-printing, but you can also work with the nested list directly.
Usage
function_tree(
pkg_name,
root = NULL,
depth = Inf,
direction = c("downstream", "upstream"),
pkg_version = NULL,
prune = NULL
)
Arguments
pkg_name |
Character scalar. Package name to analyze. |
root |
Optional. Character name of a root function to start from. If 'NULL', roots are chosen automatically: * '"downstream"' -> sources (functions with no incoming calls). * '"upstream"' -> sinks (functions with no outgoing calls). |
depth |
Integer. Maximum recursion depth. Default is 'Inf' (full depth of the package graph). |
direction |
Either '"downstream"' (caller -> callee) or '"upstream"' (callee -> caller). |
pkg_version |
Optional. If supplied, enforce that this exact version of the package is installed. Throws an error otherwise. |
prune |
Optional. Prune exported function of package at the root of function tree |
Details
The output structure is a nested list of functions where each leaf is either: * 'NULL' (true leaf, no further calls), or * a list containing '__cycle_to' to indicate a cycle in the graph.
Internally, the function uses [pkgnet::FunctionReporter] to build an igraph of function calls. Roots and neighbors are resolved from this call graph. Cycles are guarded by inserting a '__cycle_to' marker.
Value
A named list of the form: “' list( <pkg> = list( version = "<version>", <root_fn1> = list(...), <root_fn2> = list(...) ) ) “'
Examples
# Build a function tree (leaves are NULL)
ft <- function_tree("whatsnew", root = "function_tree", depth = 2,
direction = "downstream")
Get function descriptions
Description
get descriptions of exported functions
Usage
get_func_descriptions(pkg_name)
Arguments
pkg_name |
- name of the package |
Download and Parse a Specific Package Version
Description
Downloads a specified version of a CRAN package and extracts DESCRIPTION info and function names.
Usage
get_info(package_name, version, use_isolated_lib = TRUE)
Arguments
package_name |
The name of the package to download. |
version |
The version of the package to download. |
use_isolated_lib |
Logical. If TRUE, uses an isolated library path. |
Value
A list with 'desc' (DESCRIPTION fields) and 'functions' (character vector).
Examples
if (requireNamespace("dplyr", quietly = TRUE)) {
info_old <- get_info("dplyr", "1.0.9")
info_new <- get_info("dplyr", "1.1.4")
}
Extract Function Names from R Package Source
Description
Scans all R files in the specified package's R/ directory and returns a list of defined function names.
Usage
get_package_functions(pkg_source_path)
Arguments
pkg_source_path |
Character path to the untarred R package source directory. |
Value
A character vector of function names.
Read and Parse DESCRIPTION File
Description
Extracts fields from the DESCRIPTION file of a package.
Usage
get_pkg_desc(dir, fields = NULL)
Arguments
dir |
Path to the root of the untarred package source. |
fields |
Optional character vector specifying which fields to extract. If NULL, all fields are returned. |
Value
A named list of fields from the DESCRIPTION file.
Print a summary of function differences
Description
This helper function prints the differences between functions in two versions of a package. It shows which functions were added, removed, or modified, including their arguments.
Usage
print_func_diff(func_cmp, old_version, new_version)
Arguments
func_cmp |
A list with elements 'added', 'removed', and 'modified'. Each should contain function names and their argument formals. |
old_version |
The version string for the old package version. |
new_version |
The version string for the new package version. |
Value
Invisibly returns 'NULL'. Used for its side effect of printing to the console.
Print a Function Call Tree
Description
Pretty-prints a hierarchical representation of a package's **function call tree** as produced by 'function_tree_nested()'. Leaves (no further calls) are shown as plain names (their values are 'NULL'). Cycles are annotated.
Usage
print_function_tree(tree, prefix = "", last = TRUE, show_version = TRUE)
Arguments
tree |
A nested list from 'function_tree_nested()'. Either the whole object (i.e., 'list(<pkg> = list(version=..., <roots>...))') or the inner package list ('list(version=..., <roots>...)'). |
prefix |
Internal use - indentation prefix for branches (default: ""). |
last |
Internal use - whether the current node is the last at its level (default: 'TRUE'). |
show_version |
Logical; show package version at the root if available (default: 'TRUE'). |
Value
Invisibly returns 'tree' after printing.
Examples
# Build a function tree (leaves are NULL)
ft <- function_tree("whatsnew", root = "function_tree", depth = 2,
direction = "downstream")
# Print with ASCII (default)
print_function_tree(ft)