title: Splitting a graphical network string in R
body: <p>I have the following string derived from a Bayesian Network learning algorithm (like from <code>bnlearn</code> or <code>deal</code> packages):</p>
  
  <pre><code>[1] "[wst|af:bq:rloss_s:pre3][af|bq][d|wst:af:con:rloss_s][bq|con][con|af][rloss_s|af:con:pre3][pre3|af:con]"
  </code></pre>
  
  <p>The string defines the connection between variables and the direction of the connection.
  The first variable of each term in brackets (<code>[...]</code>) represents a node and all variables behind <code>|</code> represent the nodes that are connected in direction to the first node. These variables are sperated by <code>:</code>.</p>
  
  <p>I would like to transform the string into a data.frame that represents the connection between each variable. It should look like this:</p>
  
  <pre><code>&gt; data.frame(string_table)
        from      to
  1       af     wst
  2       bq     wst
  3  rloss_s     wst
  4     pre3     wst
  5       bq      af
  6      wst       d
  7       af       d
  8      con       d
  9  rloss_s       d
  10     con      bq
  11      af     con
  12      af rloss_s
  13     con rloss_s
  14    pre3 rloss_s
  15      af    pre3
  16     con    pre3
  </code></pre>