<p>A while back, I started to create an R package that would help me and my collegues at <a rel="nofollow" href="https://www.statworx.com/" target="_blank">STATWORX</a> with our daily work. After writing the <code>DESCRIPTION</code> file, I did not want to do this ever again. I found the <code>desc</code> package which let's you parse, manipulate and reformat this file via some functions and ergo a script. If you want more info on that, check out their <a rel="nofollow" href="https://github.com/r-lib/desc" target="_blank">github</a>. However, I was too lazy still, because I had to manually write the <code>NEWS</code> file.</p>
<p>I longed for the functionality of editing the <code>NEWS</code> file in the same script I built for the <code>DESCRIPTION</code> file. Since I could not find anything – and already was in a mood for programming – I wrote one my self. In this blog post, I will briefly explain what the package does.</p>
<p><img alt="" src="https://i1.wp.com/www.statworx.com/wp-content/uploads/news-logo.png?w=450&ssl=1" class="wp-image-14945" data-recalc-dims="1"></p>
<h2>Usage of <code>newsmd</code></h2>
<p>The main part of the package is the <code>news</code> object, which is an R6 class object and contains the text for the <code>NEWS.md</code> file. You can add versions, subtitles and bullet points to it via the object's methods.</p>
<h3>Initialise a new object</h3>
<p>To initialise a new object you can use two different ways:</p>
<pre><code># install.packages(&quot;devtools&quot;)
devtools::install_github(&quot;Dschaykib/newsmd&quot;)
library(newsmd)

my_news &lt;- news$new()
my_news &lt;- newsmd()
</code></pre>
<p>The default text contains markdown code and looks like this:</p>
<pre><code lang="r">## version 0.0.0.9000

---

### setup

- added NEWS.md creation
</code></pre>
<h3>Adding a the next version</h3>
<p>With <code>add_version</code> you can update the version number.</p>
<pre><code>my_news$add_version(&quot;0.0.1&quot;)
</code></pre>
<h3>Adding a new subtitle</h3>
<p>With <code>add_subtitle</code> you can add a new subtile, where the follwoing bullet points will be under.</p>
<pre><code>my_news$add_subtitle(&quot;Bugfixes&quot;)
</code></pre>
<h3>Adding more bullets</h3>
<p>With <code>add_bullet</code> you can add more bullet points to the latest version and latest subtitle. </p>
<pre><code>my_news$add_bullet(c(&quot;this is point 1&quot;, &quot;this is point 2&quot;))
</code></pre>
<h3>Getting the whole text</h3>
<p>After these fews changes, let's see how the file looks. The <code>get_text</code> method will return each single line of the file. Alternativly you can just use <code>print(my_news)</code>.</p>
<pre><code>my_news$get_text()
</code></pre>
<pre><code lang="r"> [1] &quot;## version 0.0.1&quot;        
 [2] &quot;&quot;                        
 [3] &quot;---&quot;                     
 [4] &quot;&quot;                        
 [5] &quot;&quot;                        
 [6] &quot;### Bugfixes&quot;            
 [7] &quot;&quot;                        
 [8] &quot;- this is point 1&quot;       
 [9] &quot;- this is point 2&quot;       
[10] &quot;&quot;                        
[11] &quot;&quot;                        
[12] &quot;## version 0.0.0.9000&quot;   
[13] &quot;&quot;                        
[14] &quot;---&quot;                     
[15] &quot;&quot;                        
[16] &quot;### setup&quot;               
[17] &quot;&quot;                        
[18] &quot;- added NEWS.md creation&quot;
[19] &quot;&quot; 
</code></pre>
<h3>Writing the NEWS.md file</h3>
<p>At last, with <code>write</code> you can save all your changes into the <code>NEWS.md</code> file.</p>
<pre><code>my_news$write()
</code></pre>
<h2>Combination with the <code>desc</code> package</h2>
<p>The goal of this package is to update the <code>NEWS.md</code> file in addition to the <code>DESCRIPTION</code> file. To optimize the workflow I suggest the <code>desc</code> package. For example instead of manually defining the version number, you can use <code>desc_bump_version()</code> and <code>get_version()</code> of the <code>desc</code> package:</p>
<pre><code>my_desc$bump_version(&quot;patch&quot;)
my_news$add_version(my_desc$get_version())

my_news$add_bullet(&quot;added automated creation for DESCRIPTION and NEWS.md&quot;)
</code></pre>
<p>The full example script I used for my other package, can be found <a rel="nofollow" href="https://github.com/STATWORX/helfRlein/blob/master/misc/update_DESCRIPTION_NEWS.R" target="_blank">here</a>.</p>
<h2>Conclusion</h2>
<p>I hope this little package will be of help to some of you. If you find some bugs or have ideas that would improve the usage and functionality, I would be pleased if you let me know <a rel="nofollow" href="https://github.com/Dschaykib/newsmd/issues" target="_blank">on my Github</a>.</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>Jakob ist im Statistik Team und interessiert sich im Moment stark für Hadoop und Big Data. In seiner Freizeit bastelt er gerne an alten Elektrogeräten und spielt Hockey.</p>
</div>
</div>
<p>Der Beitrag <a rel="nofollow" href="https://www.statworx.com/de/blog/an-r-package-to-create-news-md-files/" target="_blank">An R package to create NEWS.md files</a> erschien zuerst auf <a rel="nofollow" href="https://www.statworx.com/de/" target="_blank">STATWORX</a>.</p>
	<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/-zptMf2lumw" height="1">