<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/day-05-little-helper-get_network/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.statworx.com/de/blog/day-05-little-helper-get_network/"> r-bloggers – STATWORX</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>We at <a rel="nofollow" href="https://www.statworx.com/" target="_blank">STATWORX</a> work a lot with R and we often use the same little helper functions within our projects. These functions ease our daily work life by reducing repetitive code parts or by creating overviews of our projects. At first, there was no plan to make a package, but soon I realised, that it will be much easier to share and improve those functions, if they are within a package. Up till the 24th December I will present one function each day from <a rel="nofollow" href="https://github.com/STATWORX/helfRlein" target="_blank"><code>helfRlein</code></a>. So, on the 5th day of Christmas my true love gave to me…</p>
<p><img alt="door-05-get-network" src="https://i2.wp.com/www.statworx.com/wp-content/uploads/door-05-get-network.png?w=450&ssl=1" class="wp-image-16287" data-recalc-dims="1"></p>
<h2>What can it do?</h2>
<p>The aim of this little helper is to visualise the connections between R functions within a project as a flowchart. Herefore, the input is a directory path to the function or a list with the functions and the outputs are an adjacency matrix and an <code>igraph</code> object. As an example we use <a rel="nofollow" href="https://github.com/STATWORX/blog/tree/master/flowchart/R_network_functions" target="_blank">this folder with some toy functions</a>:</p>
<pre><code>net &lt;- get_network(dir = &quot;flowchart/R_network_functions/&quot;, simplify = FALSE)
g1 &lt;- net$igraph
</code></pre>
<h3>Input</h3>
<p>There are five parameters to interact with the function:</p>
<ul>
<li>a path <code>dir</code> which shall be searched.</li>
<li>a character vector <code>variations</code> with the function's definition string. The default is <code>c(&quot; &lt;- function&quot;, &quot;&lt;- function&quot;, &quot;&lt;-function&quot;)</code>.</li>
<li>a <code>pattern</code> a string with the file suffix – the default is <code>&quot;\\.R$&quot;</code>.</li>
<li>a boolean <code>simplify</code> that removes functions with no connections from the plot.</li>
<li>a named list <code>all_scripts</code> which is an alternative to <code>dir</code>. This is mainly just used for testing purposes.</li>
</ul>
<p>For a normal usage it should be enough to provide a path to the project folder.</p>
<h3>Output</h3>
<p>The given plot shows the connections of each function (arrows) and also the relative size of the function's code (size of the points). As mentioned above, the output consists of an adjacency matrix and an <code>igraph</code> object. The matrix contains the number of calls for each function. The <code>igraph</code> object has the following properties:</p>
<ul>
<li>The names of the functions are used as <strong>label</strong>.</li>
<li>The numer of lines of each function (without comments and empty one) are saved as the <strong>size</strong>.</li>
<li>The <strong>folder</strong>'s name of the first folder in the directory.</li>
<li>A <strong>color</strong> corresponding to the folder.</li>
</ul>
<p>With these properties you can improve the network plot for example like this:<br>
<img src="https://i1.wp.com/raw.githubusercontent.com/STATWORX/blog/master/flowchart/plots/improved-network.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h2>Code for example plot</h2>
<pre><code>library(igraph)

# create plots ------------------------------------------------------------
l &lt;- layout_with_fr(g1)
colrs &lt;- rainbow(length(unique(V(g1)$color)))

plot(g1,
     edge.arrow.size=.1,
     edge.width = 5*E(g1)$weight/max(E(g1)$weight),
     vertex.shape=&quot;none&quot;,
     vertex.label.color=colrs[V(g1)$color],
     vertex.label.color=&quot;black&quot;,
     vertex.size = 20,
     vertex.color = colrs[V(g1)$color],
     edge.color=&quot;steelblue1&quot;,
     layout = l)
legend(x=0,
       unique(V(g1)$folder), pch=21,
       pt.bg= colrs[unique(V(g1)$color)],
       pt.cex=2, cex=.8, bty=&quot;n&quot;, ncol=1)
</code></pre>
<h2>Overview</h2>
<p>To see all the other functions you can either check out our <a rel="nofollow" href="https://github.com/STATWORX/helfRlein" target="_blank">GitHub</a> or you can read about them <a rel="nofollow" href="https://www.statworx.com/de/tag/helfrlein/" target="_blank">here</a>.</p>
<p>Have a merry advent season!</p>
<div>
<h6>Über den Autor</h6>
<p><img src="https://i1.wp.com/www.statworx.com/wp-content/uploads/jakob-1-300x300.jpg?resize=180%2C180&ssl=1" width="180" alt="Jakob Gepp" class="wp-user-avatar wp-user-avatar-180" data-recalc-dims="1" height="180"></p>
<div>
<h4>Jakob Gepp</h4>
<p>Numbers were always my passion and as a data scientist and statistician at <a rel="nofollow" href="https://www.statworx.com/" target="_blank">STATWORX</a> I can fullfill my nerdy needs. Also I am responsable for our blog. So if you have any questions or suggestions, just send me an email!</p>
</div>
</div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<h1>ABOUT US</h1>
</div>
</div>
</div>
<hr>
<div>
<p><span><span>STATWORX</span><br></span><span>is a consulting company for data science, statistics, machine learning and artificial intelligence </span><span>located in Frankfurt, Zurich and Vienna. Sign up for our NEWSLETTER and receive reads and treats from the world of data science and AI.</span> </p>
</div>
<p><a data-x-toggle="1" tabindex="0" data-x-toggleable="e15819-7">
<p> <span>
<p><span>
<p><i data-x-icon-o=""></i></p>
<p> <span><span>Sign Up Now!</span></span> </p></span>
<p>




<p>Der Beitrag <a rel="nofollow" href="https://www.statworx.com/de/blog/day-05-little-helper-get_network/" target="_blank">Day 05 – little helper get_network</a> erschien zuerst auf <a rel="nofollow" href="https://www.statworx.com/de/" target="_blank">STATWORX</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.statworx.com/de/blog/day-05-little-helper-get_network/"> r-bloggers – STATWORX</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/UCnXfWGHZjE" height="1"></a></div></span></a></div></div></div></div>