<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/compute-visualize-drive-space-consumption-of-your-installed-r-packages/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rud.is/b/2018/04/01/compute-visualize-drive-space-consumption-of-your-installed-r-packages/"> R – rud.is</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The <code>fs</code> package makes it super quick and easy to find out just how much “package hoarding” you’ve been doing:</p>
<pre><code>library(fs)
library(ggalt) # devtools::install_github(&quot;hrbrmstr/ggalt&quot;)
library(igraph) 
library(ggraph) # devtools::install_github(&quot;thomasp85/igraph&quot;)
library(hrbrthemes) # devtools::install_github(&quot;hrbrmstr/hrbrthemes&quot;)
library(tidyverse)

installed.packages() %>%
  as_data_frame() %>%
  mutate(pkg_dir = sprintf(&quot;%s/%s&quot;, LibPath, Package)) %>%
  select(pkg_dir) %>%
  mutate(pkg_dir_size = map_dbl(pkg_dir, ~{
    fs::dir_info(.x, all=TRUE, recursive=TRUE) %>%
      summarise(tot_dir_size = sum(size)) %>% 
      pull(tot_dir_size)
  })) %>% 
  summarise(
    total_size_of_all_installed_packages=ggalt::Gb(sum(pkg_dir_size))
  ) %>% 
  unlist()
## total_size_of_all_installed_packages 
##                             &quot;1.6 Gb&quot;</code></pre>
<p>While you can modify the above and peruse the list of packages/directories in tabular format or programmatically, you can also do a bit more work to get a visual overview of package size (click/tap the image for a larger view):</p>
<pre><code>installed.packages() %>%
  as_data_frame() %>%
  mutate(pkg_dir = sprintf(&quot;%s/%s&quot;, LibPath, Package)) %>%
  mutate(dir_info = map(pkg_dir, fs::dir_info, all=TRUE, recursive=TRUE)) %>% 
  mutate(dir_size = map_dbl(dir_info, ~sum(.x$size))) -> xdf

select(xdf, Package, dir_size) %>% 
  mutate(grp = &quot;ROOT&quot;) %>% 
  add_row(grp = &quot;ROOT&quot;, Package=&quot;ROOT&quot;, dir_size=0) %>% 
  select(grp, Package, dir_size) %>% 
  arrange(desc(dir_size)) -> gdf

select(gdf, -grp) %>% 
  mutate(lab = sprintf(&quot;%s\n(%s)&quot;, Package, ggalt::Mb(dir_size))) %>% 
  mutate(lab = ifelse(dir_size > 1500000, lab, &quot;&quot;)) -> vdf

g &lt;- graph_from_data_frame(gdf, vertices=vdf)

ggraph(g, &quot;treemap&quot;, weight=dir_size) +
  geom_node_tile(fill=&quot;lightslategray&quot;, size=0.25) +
  geom_text(
    aes(x, y, label=lab, size=dir_size), 
    color=&quot;#cccccc&quot;, family=font_ps, lineheight=0.875
  ) +
  scale_x_reverse(expand=c(0,0)) +
  scale_y_continuous(expand=c(0,0)) +
  scale_size_continuous(trans=&quot;sqrt&quot;, range = c(0.5, 8)) +
  ggraph::theme_graph(base_family = font_ps) +
  theme(legend.position=&quot;none&quot;)</code></pre>
<p><a rel="nofollow" href="https://i2.wp.com/rud.is/b/wp-content/uploads/2018/04/plot_zoom_png.png?ssl=1" target="_blank"><img data-orig-file="https://i2.wp.com/rud.is/b/wp-content/uploads/2018/04/plot_zoom_png.png?fit=2874%2C1740&amp;ssl=1" data-orig-size="2874,1740" data-medium-file="https://i2.wp.com/rud.is/b/wp-content/uploads/2018/04/plot_zoom_png.png?fit=300%2C182&amp;ssl=1" data-attachment-id="9377" data-image-meta="{" data-image-description="&lt;p&gt;treemap of package disk consumption&lt;/p&gt;
" src="https://i2.wp.com/rud.is/b/wp-content/uploads/2018/04/plot_zoom_png.png?resize=780%2C472&ssl=1" data-permalink="https://rud.is/b/2018/04/01/compute-visualize-drive-space-consumption-of-your-installed-r-packages/plot_zoom_png-11/" data-large-file="https://i2.wp.com/rud.is/b/wp-content/uploads/2018/04/plot_zoom_png.png?fit=530%2C321&amp;ssl=1" alt="treemap of package disk consumption" data-image-title="treemap of package disk consumption" width="450" data-comments-opened="1" class="wp-image-9377" data-recalc-dims="1"></a></p>
<h3>Challenge</h3>
<p>Do some wrangling with the above data and turn it into a package “disk explorer” with <a rel="nofollow" href="http://twitter.com/timelyportfolio" target="_blank">@timelyportfolio</a>’s <a rel="nofollow" href="https://github.com/timelyportfolio/d3treeR" target="_blank"><code>d3treeR</code><img alt="🔗" src="https://i2.wp.com/s.w.org/images/core/emoji/2.4/72x72/1f517.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"></a> package.</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://rud.is/b/2018/04/01/compute-visualize-drive-space-consumption-of-your-installed-r-packages/"> R – rud.is</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 alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/VEuyITmmVPo" height="1"></a></div>