Analyses 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, andchain_lengthshowing 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_dfis 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)
#> === Redirect Audit Report ===
#>
#> Total rules (after NA removal): 6
#> Self-referencing redirects: 1
#> Conflicting sources: 1
#> Redirect loops: 0
#> Max chain length: 3
#>
#> --- Self-referencing redirects ---
#> from to
#> E E
#>
#> --- Conflicting sources ---
#> source targets n_targets
#> D X, Y 2
#>
#> --- Long chains (>1 hop) ---
#> from to_final chain_length in_loop
#> A final 3 FALSE
#> B final 2 FALSE
# 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
#> from to
#> 1 B C
#> 2 C final
#> 3 D X
#> 4 D Y