<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/readr-1-0-0/"></div></div><div><a data-url="https://www.r-bloggers.com/readr-1-0-0/" data-counturl="https://www.r-bloggers.com/readr-1-0-0/" data-count="horizontal" data-text="readr 1.0.0" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.rstudio.org/2016/08/05/readr-1-0-0/"> RStudio Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>readr 1.0.0 is now available on CRAN. readr makes it easy to read many types of rectangular data, including csv, tsv and fixed width files. Compared to base equivalents like <code>read.csv()</code>, readr is much faster and gives more convenient output: it never converts strings to factors, can parse date/times, and it doesn’t munge the column names. Install the latest version with:</p>
<pre><code>install.packages(&quot;readr&quot;)</code></pre>
<p>Releasing a version 1.0.0 was a deliberate choice to reflect the maturity and stability and readr, thanks largely to work by Jim Hester. readr is by no means perfect, but I don’t expect any major changes to the API in the future.</p>
<p>In this version we:</p>
<ul>
<li>Use a better strategy for guessing column types.</li>
<li>Improved the default date and time parsers.</li>
<li>Provided a full set of lower-level file and line readers and writers.</li>
<li>Fixed many bugs.</li>
</ul>
<div>
<h2>Column guessing</h2>
<p>The process by which readr guesses the types of columns has received a substantial overhaul to make it easier to fix problems when the initial guesses aren’t correct, and to make it easier to generate reproducible code. Now column specifications are printing by default when you read from a file:</p>
<pre><code>mtcars2 &lt;- read_csv(readr_example(&quot;mtcars.csv&quot;))
#> Parsed with column specification:
#> cols(
#>   mpg = col_double(),
#>   cyl = col_integer(),
#>   disp = col_double(),
#>   hp = col_integer(),
#>   drat = col_double(),
#>   wt = col_double(),
#>   qsec = col_double(),
#>   vs = col_integer(),
#>   am = col_integer(),
#>   gear = col_integer(),
#>   carb = col_integer()
#> )</code></pre>
<p>The thought is that once you’ve figured out the correct column types for a file, you should make the parsing strict. You can do this either by copying and pasting the printed column specification or by saving the spec to disk:</p>
<pre><code># Once you've figured out the correct types
mtcars_spec &lt;- write_rds(spec(mtcars2), &quot;mtcars2-spec.rds&quot;)

# Every subsequent load
mtcars2 &lt;- read_csv(
  readr_example(&quot;mtcars.csv&quot;), 
  col_types = read_rds(&quot;mtcars2-spec.rds&quot;)
)
# In production, you might want to throw an error if there
# are any parsing problems.
stop_for_problems(mtcars2)</code></pre>
<p>You can now also adjust the number of rows that readr uses to guess the column types with <code>guess_max</code>:</p>
<pre><code>challenge &lt;- read_csv(readr_example(&quot;challenge.csv&quot;))
#> Parsed with column specification:
#> cols(
#>   x = col_integer(),
#>   y = col_character()
#> )
#> Warning: 1000 parsing failures.
#>  row col               expected             actual
#> 1001   x no trailing characters .23837975086644292
#> 1002   x no trailing characters .41167997173033655
#> 1003   x no trailing characters .7460716762579978 
#> 1004   x no trailing characters .723450553836301  
#> 1005   x no trailing characters .614524137461558  
#> .... ... ...................... ..................
#> See problems(...) for more details.
challenge &lt;- read_csv(readr_example(&quot;challenge.csv&quot;), guess_max = 1500)
#> Parsed with column specification:
#> cols(
#>   x = col_double(),
#>   y = col_date(format = &quot;&quot;)
#> )</code></pre>
<p>(If you want to suppress the printed specification, just provide the dummy spec <code>col_types = cols()</code>)</p>
<p>You can now access the guessing algorithm from R: <code>guess_parser()</code> will tell you which parser readr will select.</p>
<pre><code>guess_parser(&quot;1,234&quot;)
#> [1] &quot;number&quot;

# Were previously guessed as numbers
guess_parser(c(&quot;.&quot;, &quot;-&quot;))
#> [1] &quot;character&quot;
guess_parser(c(&quot;10W&quot;, &quot;20N&quot;))
#> [1] &quot;character&quot;

# Now uses the default time format
guess_parser(&quot;10:30&quot;)
#> [1] &quot;time&quot;</code></pre>
</div>
<div>
<h2>Date-time parsing improvements:</h2>
<p>The date time parsers recognise three new format strings:</p>
<ul>
<li><code>%I</code> for 12 hour time format:
<pre><code>library(hms)
parse_time(&quot;1 pm&quot;, &quot;%I %p&quot;)
#> 13:00:00</code></pre>
<p>Note that <code>parse_time()</code> returns <code>hms</code> from the <a target="_blank" href="https://github.com/rstats-db/hms">hms</a> package, rather than a custom <code>time</code> class
<li><code>%AD</code> and <code>%AT</code> are “automatic” date and time parsers. They are both slightly less flexible than previous defaults. The automatic date parser requires a four digit year, and only accepts <code>-</code> and <code>/</code> as separators. The flexible time parser now requires colons between hours and minutes and optional seconds.
<pre><code>parse_date(&quot;2010-01-01&quot;, &quot;%AD&quot;)
#> [1] &quot;2010-01-01&quot;
parse_time(&quot;15:01&quot;, &quot;%AT&quot;)
#> 15:01:00</code></pre>
</li>

<p>If the format argument is omitted in <code>parse_date()</code> or <code>parse_time()</code>, the default date and time formats specified in the locale will be used. These now default to <code>%AD</code> and <code>%AT</code> respectively. You may want to override in your standard <code>locale()</code> if the conventions are different where you live.</p>

<div>
<h2>Low-level readers and writers</h2>
<p>readr now contains a full set of efficient lower-level readers:</p>
<ul>
<li><code>read_file()</code> reads a file into a length-1 character vector; <code>read_file_raw()</code> reads a file into a single raw vector.</li>
<li><code>read_lines()</code> reads a file into a character vector with one entry per line; <code>read_lines_raw()</code> reads into a list of raw vectors with one entry per line.</li>
</ul>
<p>These are paired with <code>write_lines()</code> and <code>write_file()</code> to efficient write character and raw vectors back to disk.</p>
</div>
<div>
<h2>Other changes</h2>
<ul>
<li><code>read_fwf()</code> was overhauled to reliably read only a partial set of columns, to read files with ragged final columns (by setting the final position/width to <code>NA</code>), and to skip comments (with the <code>comment</code> argument).</li>
<li>readr contains an experimental API for reading a file in chunks, e.g. <code>read_csv_chunked()</code> and <code>read_lines_chunked()</code>. These allow you to work with files that are bigger than memory. We haven’t yet finalised the API so please use with care, and send us your feedback.</li>
<li>There are many otherbug fixes and other minor improvements. You can see a complete list in the <a target="_blank" href="https://github.com/hadley/readr/releases/tag/v1.0.0">release notes</a>.</li>
</ul>
<p>A big thanks goes to all the community members who contributed to this release: @<a target="_blank" href="https://github.com/antoine-lizee">antoine-lizee</a>, @<a target="_blank" href="https://github.com/fpinter">fpinter</a>, @<a target="_blank" href="https://github.com/ghaarsma">ghaarsma</a>, @<a target="_blank" href="https://github.com/jennybc">jennybc</a>, @<a target="_blank" href="https://github.com/jeroenooms">jeroenooms</a>, @<a target="_blank" href="https://github.com/leeper">leeper</a>, @<a target="_blank" href="https://github.com/LluisRamon">LluisRamon</a>, @<a target="_blank" href="https://github.com/noamross">noamross</a>, and @<a target="_blank" href="https://github.com/tvedebrink">tvedebrink</a>.</p>
</div>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rstudioblog.wordpress.com/3000/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/rstudioblog.wordpress.com/3000/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/readr-1-0-0/"></div></div><div><a data-url="https://www.r-bloggers.com/readr-1-0-0/" data-counturl="https://www.r-bloggers.com/readr-1-0-0/" data-count="vertical" data-text="readr 1.0.0" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://blog.rstudio.org/2016/08/05/readr-1-0-0/"> RStudio 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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/tbL0PJz-__4"></a></div></ul></div>