audit_redirects: Audit Redirect Rules

View source: R/audit_redirects.R

audit_redirectsR Documentation

Audit Redirect Rules

Description

Analyzes a redirect data frame and returns a diagnostic report covering chain lengths, loops, conflicting sources, self-referencing redirects, and terminal destinations. Useful as a pre-flight check before running resolve_redirects or pagerank.

Usage

audit_redirects(
  redirects_df,
  edge_list_df = NULL,
  redirect_from_col = "from",
  redirect_to_col = "to",
  edge_from_col = "from",
  edge_to_col = "to"
)

Arguments

redirects_df

A data frame containing redirect rules.

edge_list_df

Optional data frame of edges. If provided, orphaned redirects (rules whose source URL does not appear in the edge list) are identified.

redirect_from_col

Character, name of the source column in redirects_df. Default "from".

redirect_to_col

Character, name of the target column in redirects_df. Default "to".

edge_from_col

Character, name of the source column in edge_list_df. Default "from".

edge_to_col

Character, name of the target column in edge_list_df. Default "to".

Value

A list with class "redirect_audit" containing:

n_rules

Total number of redirect rules (after NA removal).

n_self_refs

Number of self-referencing redirects (from == to).

self_refs

Data frame of self-referencing redirects.

n_conflicts

Number of source URLs with conflicting targets.

conflicts

Data frame listing each conflicting source and its distinct targets.

n_loops

Number of redirect loops detected.

loops

List of character vectors, each describing a cycle path.

chains

Data frame with columns from, to_final, and chain_length showing the terminal destination and hop count for every source URL.

max_chain_length

Maximum chain length found.

orphaned_redirects

Data frame of redirect sources not found in the edge list (only when edge_list_df is provided).

Examples

redirects <- data.frame(
  from = c("A", "B", "C", "D", "D", "E"),
  to = c("B", "C", "final", "X", "Y", "E")
)
audit <- audit_redirects(redirects)
print(audit)

# With an edge list to detect orphaned redirects
edges <- data.frame(from = "Z", to = "A")
audit2 <- audit_redirects(redirects, edge_list_df = edges)
audit2$orphaned_redirects

pagerankr documentation built on Oct. 1, 2026, 5:09 p.m.