Walks links breadth first from one or more start cards. Rows are ordered by distance, then the order of cards in
the map. When several links reach a card at the same distance, the first in links order wins. Every card and link
in the map counts: hidden cards, variants and the changes of add_steps() are ignored.
Usage
sm_trace(
map,
ids,
...,
direction = c("downstream", "upstream", "both"),
kinds = NULL,
max_distance = Inf
)Arguments
- map
A
stage_map()widget.- ids
Card ids to start from, as text (a factor counts as text) or whole numbers (never
NA, never blank).NULLor a length-zero vector returns no rows.- ...
Must stay empty. It makes every argument after it a named argument, and a typo in an argument's name an error that names it.
- direction
Which way to follow links:
"downstream"(the default, fromfromtoto),"upstream"(fromtotofrom), or"both".- kinds
Link kind ids to follow, as text (a factor counts as text) or whole numbers (never
NA, never blank).NULL, the default, follows every link, including links without a kind.character(0)follows no links.- max_distance
Maximum number of links to follow: a whole number from
0, orInf(the default, no limit).0returns only the start cards.
Value
A plain data frame with row names 1 to n and columns:
id,label,stage,lane(character): the card's id, label, stage id and lane id.direction(character):"start"for a start card,"downstream","upstream", or"both"when both walks reach the card. NeverNA.distance(integer): number of links from a start card (0Lfor start cards).through(character): id of the card this card was reached from, nearer the start (NAfor start cards). In an upstream row the link itself runs fromidtothrough; in a"both"row it may run either way.kind(character): kind id of the link that reached this card (NAfor start cards and unlabelled links).
With empty ids, the data frame has zero rows and the same column types. A wrong map stops with
stagemap_error_widget; an id or kind not in the map stops with stagemap_error_id.
Details
With direction = "both", the downstream and upstream walks run apart from the start cards and are joined, so a
trace never follows one link downstream and the next upstream. A card reached by both walks (in a loop, or between
two start cards) appears once with direction = "both", the shorter distance, and the through and kind of
that walk; on a tie, the downstream walk wins. Because such a card is one row, through does not say which way its
link runs (look in links), and distance is not always the distance of the through card plus 1: the
through column forms a path only within one walk, and the row of a "both" card may come from the other walk.
See also
Other trace:
sm_missing(),
sm_orphans()
Examples
map <- stage_map(
cards = data.frame(
id = c("req-1", "tst-1", "res-1"),
label = c("Requirement", "Test", "Result"),
stage = c("req", "test", "result"),
lane = "core"
)
) |>
add_links(
data.frame(
from = c("req-1", "tst-1"),
to = c("tst-1", "res-1"),
kind = c("verifies", "produces")
),
kinds = data.frame(
id = c("verifies", "produces"),
label = c("Verifies", "Produces")
)
)
sm_trace(map, "req-1")
#> id label stage lane direction distance through kind
#> 1 req-1 Requirement req core start 0 <NA> <NA>
#> 2 tst-1 Test test core downstream 1 req-1 verifies
#> 3 res-1 Result result core downstream 2 tst-1 produces