<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/epubr-0-5-0-cran-release/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://leonawicz.github.io/post/epubr-0-5-0-cran-release/"> Matt's R Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The <a rel="nofollow" href="https://github.com/ropensci/epubr" target="_blank">epubr</a> package provides functions supporting the reading and parsing of internal e-book content from EPUB files. This post briefly highlights the changes from v0.4.0. See the <a rel="nofollow" href="https://ropensci.github.io/epubr/articles/epubr.html" target="_blank">vignette</a> for a more comprehensive introduction.</p>
<div>
<h2>Minor addition</h2>
<p>There is not much to see with the upgrade to version 0.5.0. Only one user function has been added, <code>epub_cat</code>. All this does is allow you to <code>cat</code> chunks of parsed e-book text to the console in a more readable manner. This can be helpful to get a quick glimpse of the content you are working with in a way that is easier on the eyes than looking at table entries and object structures.</p>
<p>Arguments to <code>epub_cat</code> give you control over the formatting. It is not intended to serve any other purposes beyond this human-guided content inspection. Arguments include:</p>
<ul>
<li><code>max_paragraphs</code></li>
<li><code>skip</code></li>
<li><code>paragraph_spacing</code></li>
<li><code>paragraph_indent</code></li>
<li><code>section_sep</code></li>
<li><code>book_sep</code></li>
</ul>
<p>See the help documentation for details.</p>
</div>
<div>
<h2>Minor change</h2>
<p><code>epub_cat</code>, and now <code>epub_head</code> for consistency, take a more generic-sounding first argument <code>x</code> as a data argument, rather than <code>data</code> or <code>file</code>. This is because these summary functions can now be used on a filename string pointing to an external EPUB file that does not otherwise need to be read into R or, alternatively, a data frame already read into R by <code>epub</code>. This allows you to avoid reading the files from disk multiple times if the data is already in your R session.</p>
<div>
<h3>Some context around <code>epub_cat</code></h3>
<p>Also, notice that this operates on paragraphs, not lines, if by lines I meant sentences. Since this level of information has not been stripped from the text that has been read in, it can be used. This may not mean the same thing in every section of every e-book, but the general idea is that <code>epub_cat</code> respects line breaks in the text. It pays attention to where they are and where they are not. I chose to call these paragraphs; it’s the label that is by far most often the correct one. But a one-line title or even the distinct lines of text on the copyright page of an e-book would all be treated the same way.</p>
<p>Control ends there of course. For example, you cannot stipulate that a title line should be excluded from indenting. Remember that the purpose of <code>epubr</code> is to bring in <em>text</em> for analysis, while preserving much (but not all) of its structure. I.e., you want “only the text” to operate on with ease, but you also don’t want to be relegated to a single, gigantic character string (that may not even be in the correct order) that aggregates out potential variables that could be mapped to sections of text and their sequence. <code>epubr</code> is not intended to retain all the the XML tags that define the appearance of the original document. The fundamental purpose of <code>epubr</code> is to strip that out entirely.</p>
<p>Here is an example:</p>
<pre><code>library(epubr)
file &lt;- system.file(&quot;dracula.epub&quot;, package = &quot;epubr&quot;)
(x &lt;- epub(file))
#> # A tibble: 1 x 9
#>   rights  identifier   creator  title language subject date  source  data 
#>   </code></pre></div></div>