title: How to retrieve the original graph from a vertex list
body: <h2>Problem</h2>
  <p>Does the <code>igraph</code> package provide an interface to retrieve the original graph from a sub selection of vertices? There is for sure some internal way of doing it, as a simple <code>print</code> shows the total number of vertices in the graph as well as the number of selected vertices and through retro-engineering I was able to get the original graph, but I was wondering whether there is a way supported by the API rather than relying on internal commands.</p>
  <p>Code speaks more than words, so here's what I mean:</p>
  <pre class="lang-r prettyprint-override"><code>library(igraph)
  
  G &lt;- make_ring(10)
  (v &lt;- V(G)[1:3])
  ### This output tells me that `v` &quot;knows&quot; about the graph it is taken from
  ### (namely that it has 10 vertices)
  ## + 3/10 vertices, from 3fe4e83:
  ## [1] 1 2 3
  </code></pre>
  <p>The relevant part can be extracted from <code>igraph:::print.igraph.vs</code></p>
  <pre class="lang-r prettyprint-override"><code>### igraph:::print.igraph.vs
  graph &lt;- get_vs_graph(x)
  
  ### igraph:::get_vs_graph
  at &lt;- attr(seq, &quot;env&quot;)
  if (class(at) == &quot;weakref&quot;) {
     weak_ref_key(at)$me
  }
  </code></pre>
  <p>That is, I could do something like:</p>
  <pre class="lang-r prettyprint-override"><code>all.equal(G, igraph:::get_vs_graph(v))
  ## TRUE
  </code></pre>
  <p>But of course we are using an internal function. So I was wondering whether the API would provide a dedicated way of getting the original graph or whether this is not foreseen?</p>
  <h2>Why?</h2>
  <p>Actually, I have a list of vertex sequences coming all from different graphs. Ideally I would like to get a ratio of the number of vertices in my list by the number of vertices in the respective original graph:</p>
  <pre class="lang-r prettyprint-override"><code>set.seed(1)
  Gs &lt;- lapply(10 ^ (1:4), make_ring)
  Vs &lt;- lapply(Gs, function(G) V(G)[seq(1, sample(gorder(G), 1))])
  
  sapply(Vs, function(v) length(v) / gorder(igraph:::get_vs_graph(v)))
  ## [1] 0.9000 0.6800 0.6790 0.9725
  </code></pre>