Q:

How to subset a large igraph to just one node and its connected nodes using R?

I have a very large igraph (called g) in R.
I am just interested in one node (NodeA) plus whatever nodes are directly connected to NodeA.  I want to end up with a very simple graph like the picture below.
I have tried subgraph(g, "nodeA") but I just end up with NodeA all by itself.
I think I need to subset the edges of graph g to those that connect to nodeA then use subgraph.edges().  I can't figure out how to subset the edges based on what nodes they are connected to...

A:

Try using neighbors()
# Example graph
g1 <- graph_from_literal(1:2:3---3:4:5)

# Let's take a look at it
plot(g1)

# Say we are interested in the subgraph consisting of vertex 1 and all
# other vertices it is connected to

g2 <- induced_subgraph(g1, c(1, neighbors(g1,1)))
plot(g2)

