<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/running-the-same-task-in-python-and-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.win-vector.com/blog/2018/10/running-the-same-task-in-python-and-r/"> R – Win-Vector Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>According to <a rel="nofollow" href="https://www.kdnuggets.com/2017/08/python-overtakes-r-leader-analytics-data-science.html" target="_blank">a KDD poll</a> <em>fewer</em> respondents (by rate) used <em>only</em> <a rel="nofollow" href="https://www.r-project.org/" target="_blank"><code>R</code></a> in 2017 than in 2018. At the same time more respondents (by rate) used only <code>Python</code> in 2017 than in 2016.</p>
<p>Let’s take this as an excuse to take a quick look at what happens when we try a task in both systems.</p>
<p><span></span></p>
<p>
<p>For our task we picked the painful exercise of directly reading a 50,000,000 row by 50 column data set into memory on a machine with only 8GB of ram.</p>
<p>In <code>Python</code> the <code>Pandas</code> package takes around 6 minutes to read the data, and then one is ready to work.</p>
<p><img border="0" src="https://i2.wp.com/www.win-vector.com/blog/wp-content/uploads/2018/10/read_python.png?resize=379%2C223" alt="Read python" width="379" title="read_python.png" data-recalc-dims="1" height="223"></p>
<p>In <code>R</code> both <code>utils::read.csv()</code> and <code>readr::read_csv()</code> fail with out of memory messages. So if your view of <code>R</code> is “<code>base R</code> only”, or “<code>base R</code> plus <code>tidyverse</code> only”, or “<code>tidyverse</code> only”: reading this file is a “hard task.”</p>
<p><img border="0" src="https://i0.wp.com/www.win-vector.com/blog/wp-content/uploads/2018/10/read_r_1.png?resize=559%2C270" alt="Read r 1" width="450" title="read_r_1.png" data-recalc-dims="1"></p>
<p>With the above narrow view one would have no choice but to move to <code>Python</code> if one wants to get the job done.</p>
<p>Or, we could remember <a rel="nofollow" href="https://cran.r-project.org/package=data.table" target="_blank"><code>data.table</code></a>. While <code>data.table</code> is obviously not part of the <code>tidyverse</code>, <code>data.table</code> has been a best-practice in <code>R</code> for around 12 years. It can read the data and is ready to work in <code>R</code> in under a minute.</p>
<p><img border="0" src="https://i1.wp.com/www.win-vector.com/blog/wp-content/uploads/2018/10/read_r_2.png?resize=238%2C131" alt="Read r 2" width="238" title="read_r_2.png" data-recalc-dims="1" height="131"></p>
<p>In conclusion, to get things done in a pinch: learn <code>Python</code> or learn <code>data.table</code>. And, in my opinion, “<code>tidyverse</code> first teaching” (commonly code for “<code>tidyverse</code> only teaching”) may not serve the <code>R</code> community well in the long run.</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="http://www.win-vector.com/blog/2018/10/running-the-same-task-in-python-and-r/"> R – Win-Vector Blog</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/0Gmy7QK1XEw" height="1"></a></div>