Skip to contents

Applies redirect rules to an edge list and returns the resolved link graph without computing PageRank. Useful for inspecting what the link graph looks like after redirects are applied, deduplication, and optional URL cleaning.

Usage

resolve_links(
  edge_list_df,
  redirects_df = NULL,
  clean_urls = TRUE,
  self_loops = c("drop", "keep"),
  edge_from_col = "from",
  edge_to_col = "to",
  redirect_from_col = "from",
  redirect_to_col = "to",
  duplicate_from_policy = c("strict", "first_wins", "last_wins", "most_frequent",
    "prune_source", "resolve_if_consistent"),
  loop_handling = c("error", "prune_loop", "break_arrow"),
  rurl_params = list()
)

Arguments

edge_list_df

A data frame representing the edge list with at least two columns for source and target URLs.

redirects_df

A data frame containing redirect rules with 'from' and 'to' columns (or as specified by `redirect_from_col`/`redirect_to_col`). If `NULL`, no redirects are applied.

clean_urls

Logical, whether to clean/normalize URLs using rurl::clean_url before resolving. Default `TRUE`.

self_loops

Character, how to handle self-loops created after redirect resolution. One of `"drop"` (default) or `"keep"`.

edge_from_col, edge_to_col

Names of the from/to columns in `edge_list_df`. Default `"from"` and `"to"`.

redirect_from_col, redirect_to_col

Names of the from/to columns in `redirects_df`. Default `"from"` and `"to"`.

duplicate_from_policy

How to handle conflicting redirects. Passed through to [resolve_redirects()]. Default `"strict"`.

loop_handling

How to handle redirect cycles. Passed through to [resolve_redirects()]. Default `"error"`.

rurl_params

Named list of additional arguments passed to rurl::clean_url when `clean_urls = TRUE`.

Value

A data frame with the same columns as `edge_list_df`, but with URLs replaced by their final redirect destinations, duplicate edges removed, and self-loops handled according to `self_loops`.

Examples

edges <- data.frame(
  from = c("A", "B", "C", "A"),
  to = c("B", "C", "D", "B")
)
redirects <- data.frame(
  from = c("B", "C"),
  to = c("B_final", "C_final")
)
resolve_links(edges, redirects, clean_urls = FALSE)
#>      from      to
#> 1       A B_final
#> 2 B_final C_final
#> 3 C_final       D

# Without redirects: just deduplicate and clean
resolve_links(edges, clean_urls = FALSE)
#>   from to
#> 1    A  B
#> 2    B  C
#> 3    C  D

# Inspect the graph before and after a redirect change
before <- resolve_links(edges, clean_urls = FALSE)
new_redirects <- data.frame(
  from = "D", to = "B_final"
)
after <- resolve_links(edges, new_redirects, clean_urls = FALSE)