# How to output all directed edges in a (causal) path from a node A to another node B

**URL:** <https://igraph.discourse.group/t/how-to-output-all-directed-edges-in-a-causal-path-from-a-node-a-to-another-node-b/1547>\
**Category:** Usage\
**Tags:** R\
**Created:** [5 May 2023 03:54 UTC](https://igraph.discourse.group/t/how-to-output-all-directed-edges-in-a-causal-path-from-a-node-a-to-another-node-b/1547 "2023-05-05T03:54:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fcui](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/fcui/32/937_2.png) [@fcui](https://igraph.discourse.group/u/fcui)\
**Post date:** [5 May 2023 03:54 UTC](https://igraph.discourse.group/t/how-to-output-all-directed-edges-in-a-causal-path-from-a-node-a-to-another-node-b/1547/1 "2023-05-05T03:54:23Z")

</div>

Hi, I’m new to graph. Suppose I have an acyclic directed mixed graph like the following code.

```auto
g <- graph.formula(x -+ w1, x -+ y1, w1 -+ w2, w2 -+ y2,
                   w1 -+ y1, y1 -+ w1, w1 -+ w2, w2 -+ w1, w1 -+ y2, y2 -+ w1, w2 -+ x, x -+ w2, simplify = FALSE)
g <- set.edge.attribute(graph = g, name = "description", index = 5:12, value = "U")

```

Say I’m interested in the path from x to y2 (x → w1 → w2 → y2). Is there a function/way to output the directed edges between them? The output is a set like this: x -+ w1, w1 -+ w2, w2 -+ y2.

Thanks in advance for any help or insights!

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [5 May 2023 06:32 UTC](https://igraph.discourse.group/t/how-to-output-all-directed-edges-in-a-causal-path-from-a-node-a-to-another-node-b/1547/2 "2023-05-05T06:32:37Z")

</div>

> [@fcui](#):
>
> Say I’m interested in the path from x to y2 (x → w1 → w2 → y2). Is there a function/way to output the directed edges between them?

`shortest_paths()` will find a shortest path between two vertices. The `output` parameter controls whether to output the vertices along the path, the edges along the path, or both. See [Shortest (directed or undirected) paths between vertices — distance\_table • igraph](https://r.igraph.org/reference/distances.html)

Example:

```auto
> shortest_paths(g, 'x', 'y2', output='epath')$epath
[[1]]
+ 2/12 edges from 3bcf07b (vertex names):
[1] x ->w1 w1->y2

```

> [@fcui](#):
>
> Suppose I have an acyclic directed mixed graph like the following code.

This graph is not acyclic. There are reciprocal edges like y1 ↔ w1. That’s a 2-cycle. x → w1 → w2 → x is a 3-cycle.

“mixed graph” normally refers to a graph that contains both directed and undirected edges. igraph does not support mixed graphs. Did you mean multigraph?
