<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://info.stat.cmu.edu/index.php?action=history&amp;feed=atom&amp;title=Developing_R_packages</id>
	<title>Developing R packages - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://info.stat.cmu.edu/index.php?action=history&amp;feed=atom&amp;title=Developing_R_packages"/>
	<link rel="alternate" type="text/html" href="https://info.stat.cmu.edu/index.php?title=Developing_R_packages&amp;action=history"/>
	<updated>2026-11-05T19:39:36Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://info.stat.cmu.edu/index.php?title=Developing_R_packages&amp;diff=808&amp;oldid=prev</id>
		<title>Ajshen at 03:13, 29 June 2026</title>
		<link rel="alternate" type="text/html" href="https://info.stat.cmu.edu/index.php?title=Developing_R_packages&amp;diff=808&amp;oldid=prev"/>
		<updated>2026-06-29T03:13:41Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 03:13, 29 June 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Package Development and Distribution]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This wiki presents a motivational example of a lot of properties of R packages and how to use them. Please see [[packages motivation]] for motivation about why you should utilize the package framework while doing research. The material in this page captures thoughts from lots of people and is a rewriting of a lecture Ben LeRoy presented while teaching 36-350 in the summer of 2019. Additionally, there are a lot of useful resources on the web to help you make an &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package including:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This wiki presents a motivational example of a lot of properties of R packages and how to use them. Please see [[packages motivation]] for motivation about why you should utilize the package framework while doing research. The material in this page captures thoughts from lots of people and is a rewriting of a lecture Ben LeRoy presented while teaching 36-350 in the summer of 2019. Additionally, there are a lot of useful resources on the web to help you make an &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package including:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key infowiki:diff:1.41:old-65:rev-808:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Ajshen</name></author>
	</entry>
	<entry>
		<id>https://info.stat.cmu.edu/index.php?title=Developing_R_packages&amp;diff=65&amp;oldid=prev</id>
		<title>Skipper at 01:49, 24 May 2024</title>
		<link rel="alternate" type="text/html" href="https://info.stat.cmu.edu/index.php?title=Developing_R_packages&amp;diff=65&amp;oldid=prev"/>
		<updated>2024-05-24T01:49:42Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 01:49, 24 May 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l294&quot;&gt;Line 294:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 294:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;and R will run all your associated test, and will return output like seen in the following image:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;and R will run all your associated test, and will return output like seen in the following image:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[File:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;devtool_test_example&lt;/del&gt;.png|&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;frameless&lt;/del&gt;|&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;600px&lt;/del&gt;|&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;alt=output of testthat&lt;/del&gt;|output of testthat]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[File:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Devtool test example&lt;/ins&gt;.png|&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;600px&lt;/ins&gt;|&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;frame&lt;/ins&gt;|&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;left&lt;/ins&gt;|output of testthat]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/li&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/li&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/ol&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/ol&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key infowiki:diff:1.41:old-63:rev-65:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Skipper</name></author>
	</entry>
	<entry>
		<id>https://info.stat.cmu.edu/index.php?title=Developing_R_packages&amp;diff=63&amp;oldid=prev</id>
		<title>Skipper at 01:48, 24 May 2024</title>
		<link rel="alternate" type="text/html" href="https://info.stat.cmu.edu/index.php?title=Developing_R_packages&amp;diff=63&amp;oldid=prev"/>
		<updated>2024-05-24T01:48:06Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 01:48, 24 May 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l73&quot;&gt;Line 73:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 73:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;and anything else you included from intializing your git repo (&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LICENSE&amp;lt;/code&amp;gt;, etc)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;and anything else you included from intializing your git repo (&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LICENSE&amp;lt;/code&amp;gt;, etc)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[File:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Tartan_folder&lt;/del&gt;.png|frameless|&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;600px|alt=initial directory items&lt;/del&gt;|initial directory items]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[File:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1200px-Tartan folder&lt;/ins&gt;.png&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|600px&lt;/ins&gt;|frameless|&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;left&lt;/ins&gt;|initial directory items]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== Description file meta-data ====&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== Description file meta-data ====&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l79&quot;&gt;Line 79:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 79:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The first thing you should do is update a little bit of the meta-data in the &amp;lt;code&amp;gt;DESCRIPTION&amp;lt;/code&amp;gt; file, an example of which is seen below. You don’t need to add lots, but you’ll probably want to at least add your name and a title.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The first thing you should do is update a little bit of the meta-data in the &amp;lt;code&amp;gt;DESCRIPTION&amp;lt;/code&amp;gt; file, an example of which is seen below. You don’t need to add lots, but you’ll probably want to at least add your name and a title.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[File:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;tartan_description&lt;/del&gt;.png|frameless|&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;600px|alt=initialized description file&lt;/del&gt;|initialized description file]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[File:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Tartan description&lt;/ins&gt;.png&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|600px&lt;/ins&gt;|frameless|&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;left&lt;/ins&gt;|initialized description file]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Step 2: Writing a function ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Step 2: Writing a function ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l205&quot;&gt;Line 205:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 205:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;devtools::load_all()&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;devtools::load_all()&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;?call_scotty_demo&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;?call_scotty_demo&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[File:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;call_scotty_demo_doc&lt;/del&gt;.png|frameless|&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;600px|alt=example of help file&lt;/del&gt;|example of help file]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[File:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Call scotty demo doc&lt;/ins&gt;.png&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|600px&lt;/ins&gt;|frameless|&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;left&lt;/ins&gt;|example of help file]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Step 4: Testing ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Step 4: Testing ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key infowiki:diff:1.41:old-18:rev-63:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Skipper</name></author>
	</entry>
	<entry>
		<id>https://info.stat.cmu.edu/index.php?title=Developing_R_packages&amp;diff=18&amp;oldid=prev</id>
		<title>Skipper: Created page with &quot;This wiki presents a motivational example of a lot of properties of R packages and how to use them. Please see packages motivation for motivation about why you should util...&quot;</title>
		<link rel="alternate" type="text/html" href="https://info.stat.cmu.edu/index.php?title=Developing_R_packages&amp;diff=18&amp;oldid=prev"/>
		<updated>2024-03-29T23:48:17Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This wiki presents a motivational example of a lot of properties of R packages and how to use them. Please see &lt;a href=&quot;/index.php?title=Packages_motivation&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Packages motivation (page does not exist)&quot;&gt;packages motivation&lt;/a&gt; for motivation about why you should util...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This wiki presents a motivational example of a lot of properties of R packages and how to use them. Please see [[packages motivation]] for motivation about why you should utilize the package framework while doing research. The material in this page captures thoughts from lots of people and is a rewriting of a lecture Ben LeRoy presented while teaching 36-350 in the summer of 2019. Additionally, there are a lot of useful resources on the web to help you make an &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package including:&lt;br /&gt;
&lt;br /&gt;
* [http://r-pkgs.had.co.nz R Packages]. ~Hadley Wickham&lt;br /&gt;
* [https://link.springer.com/book/10.1007/978-0-387-75936-4 Software for Data Analysis: Programming with R.] ~John Chambers&lt;br /&gt;
* [https://cran.r-project.org/doc/manuals/r-release/R-exts.html Writing R Extensions] (the official documentation)&lt;br /&gt;
&lt;br /&gt;
What’s nice about the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; programming language how many easy-to-use resources there are to help you develop your own package. The following quote captures a notation that if you’re going to be working with R for long enough, package-driven development is going to happen - so why don’t you start now?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;“… from user to programmer to contributor, in the gradual progress that R encourages.” ~ John Chambers (Software for Data Analysis: Programming with R)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Foundations (what tools will be used) ==&lt;br /&gt;
&lt;br /&gt;
Currently, there are few very powerful packages to help you develop an &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package as painlessly as possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;devtools&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;usethis&amp;lt;/code&amp;gt; packages provide a set of functions to automate higher level package details and repeative package development demands&lt;br /&gt;
* &amp;lt;code&amp;gt;Roxygen2&amp;lt;/code&amp;gt; helps rapid and standardized documentation for your package&lt;br /&gt;
* &amp;lt;code&amp;gt;testthat&amp;lt;/code&amp;gt; provides clean and standardized tools for testing&lt;br /&gt;
&lt;br /&gt;
== Building an R package ==&lt;br /&gt;
&lt;br /&gt;
=== Step 0: Setting up a Github repo and a Rstudio project directory ===&lt;br /&gt;
&lt;br /&gt;
Version control (and discussed in Stat Computing) is a very useful tool to help streamline file management and provide piece of mind. Oftentimes, you will want to have a copy of the repository not just on your personal computer but online (to help with sharing, just in case your computer dies, it’s cool, etc.). As such these steps will walk you through how to set up a github repo for your new package and how to connect that repo to a new project in R studio.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;#039;&amp;#039;&amp;#039;In &amp;lt;code&amp;gt;GitHub&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039;, do the following:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;go to the top-level directory (i.e., &amp;lt;code&amp;gt;github.com/&amp;lt;your user name&amp;gt;&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;click on “+” at top right, and select “New repository” &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;name the repository (e.g., “tartan”) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;provide a short description of the repository (don’t leave completely blank!) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;keep the repository public (as students you have access to free private repos https://education.github.com/pack, but for purposes of this example we will keep the repo public) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;click on “Initialize this repository with a README” and select the R option in “Add .gitignore”… there is no need to “Add a license” &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;click on “Create Repository” &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;#039;&amp;#039;&amp;#039;…then in RStudio&amp;#039;&amp;#039;&amp;#039;, do the following:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;click on &amp;lt;code&amp;gt;File &amp;gt; New Project...&amp;lt;/code&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;click on “Version Control”, then on “Git” &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;provide the &amp;#039;&amp;#039;full&amp;#039;&amp;#039; address for the “Repository URL” (including the &amp;lt;code&amp;gt;https&amp;lt;/code&amp;gt;, etc.; by default, this will provide the name of your local repository)  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;make sure “Create project as subdirectory of:” points to where you want to point it &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;click on “Create Project” (in this example we will be calling our package &amp;lt;code&amp;gt;tartan&amp;lt;/code&amp;gt;) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Creating a minimal source package ===&lt;br /&gt;
&lt;br /&gt;
An R (&amp;#039;&amp;#039;source&amp;#039;&amp;#039;) package just files in a directory, formatted in a specific way.&lt;br /&gt;
&lt;br /&gt;
To create the bare bones R package, just type in your Rstudio console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;usethis::create_package(&amp;quot;tartan&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;# output of the above command&lt;br /&gt;
&amp;gt; usethis::create_package(&amp;quot;tartan&amp;quot;)&lt;br /&gt;
✔ Setting active project to &amp;#039;./tartan&amp;#039;&lt;br /&gt;
✔ Creating &amp;#039;R/&amp;#039;&lt;br /&gt;
✔ Creating &amp;#039;man/&amp;#039;&lt;br /&gt;
✔ Writing &amp;#039;DESCRIPTION&amp;#039;&lt;br /&gt;
✔ Writing &amp;#039;NAMESPACE&amp;#039;&lt;br /&gt;
✔ Changing working directory to &amp;#039;./tartan&amp;#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* if in the &amp;lt;code&amp;gt;tartan&amp;lt;/code&amp;gt; project, may need to do &amp;lt;code&amp;gt;setwd(&amp;amp;quot;../&amp;amp;quot;)&amp;lt;/code&amp;gt;, run the above line and then do &amp;lt;code&amp;gt;setwd(&amp;amp;quot;tartan&amp;amp;quot;)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This will create a &amp;lt;code&amp;gt;tartan&amp;lt;/code&amp;gt; folder with the following items:&lt;br /&gt;
&lt;br /&gt;
# Directory &amp;lt;code&amp;gt;R/&amp;lt;/code&amp;gt; (where all the function source code goes)&lt;br /&gt;
# Directory &amp;lt;code&amp;gt;man/&amp;lt;/code&amp;gt; (where all the &amp;lt;code&amp;gt;Roxygen&amp;lt;/code&amp;gt; created documentation goes &amp;#039;&amp;#039;&amp;#039;- auto generated&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
# &amp;lt;code&amp;gt;NAMESPACE&amp;lt;/code&amp;gt; file (information about what functions you’re providing the user &amp;#039;&amp;#039;&amp;#039;- auto generated&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
# &amp;lt;code&amp;gt;DESCRIPTION&amp;lt;/code&amp;gt; file (information about your package)&lt;br /&gt;
# &amp;lt;code&amp;gt;tartan.Rproj&amp;lt;/code&amp;gt; file (if using RStudio - just R project information &amp;#039;&amp;#039;&amp;#039;- auto generated&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
and anything else you included from intializing your git repo (&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;LICENSE&amp;lt;/code&amp;gt;, etc)&lt;br /&gt;
&lt;br /&gt;
[[File:Tartan_folder.png|frameless|600px|alt=initial directory items|initial directory items]]&lt;br /&gt;
&lt;br /&gt;
==== Description file meta-data ====&lt;br /&gt;
&lt;br /&gt;
The first thing you should do is update a little bit of the meta-data in the &amp;lt;code&amp;gt;DESCRIPTION&amp;lt;/code&amp;gt; file, an example of which is seen below. You don’t need to add lots, but you’ll probably want to at least add your name and a title.&lt;br /&gt;
&lt;br /&gt;
[[File:tartan_description.png|frameless|600px|alt=initialized description file|initialized description file]]&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Writing a function ===&lt;br /&gt;
&lt;br /&gt;
All of your R code needs to go in &amp;lt;code&amp;gt;.R&amp;lt;/code&amp;gt; files in the &amp;lt;code&amp;gt;R/&amp;lt;/code&amp;gt; directory. You can create these files yourself, but you can also automate this with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;usethis::use_r(&amp;quot;welcome&amp;quot;) # opens up file (creates if need be)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
With the previous line of code creating an empty &amp;lt;code&amp;gt;R/welcome.R&amp;lt;/code&amp;gt; file. &amp;lt;br&amp;gt; Inside this file, let’s image we add the following function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;call_scotty_demo &amp;lt;- function(your_name) {&lt;br /&gt;
  if (nchar(your_name) &amp;gt; 30){&lt;br /&gt;
    warning(&amp;quot;your name is beyond 30 characters, and has been truncated&amp;quot;)&lt;br /&gt;
    your_name &amp;lt;- substr(your_name, 1, 30)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  name_length &amp;lt;- nchar(your_name)&lt;br /&gt;
&lt;br /&gt;
  # Hiiiii&lt;br /&gt;
  cat(paste(&amp;quot;\n&amp;quot;,&lt;br /&gt;
    paste0(c(&amp;quot;&amp;quot;, rep(&amp;quot;-&amp;quot;, name_length + 8), &amp;quot;\n&amp;quot;), collapse = &amp;quot;&amp;quot;),&lt;br /&gt;
    paste0(c(&amp;quot;| Hi &amp;quot;, your_name, &amp;quot;! | \n&amp;quot;), collapse=&amp;quot;&amp;quot;),&lt;br /&gt;
    paste0(c(&amp;quot;|   &amp;quot;, rep(&amp;quot;-&amp;quot;, name_length + 4), &amp;quot;\n&amp;quot;), collapse = &amp;quot;&amp;quot;),&lt;br /&gt;
    paste0(c(&amp;quot;| /\n&amp;quot;)))&lt;br /&gt;
  )&lt;br /&gt;
&lt;br /&gt;
  # from Scotty.&lt;br /&gt;
  cat(paste0(&lt;br /&gt;
      &amp;quot; |/  |\\_/|          \n&amp;quot;,&lt;br /&gt;
      &amp;quot; |   |q p|   /}      \n&amp;quot;,&lt;br /&gt;
      &amp;quot; |   ( 0 )\&amp;quot;\&amp;quot;\&amp;quot;\\   \n&amp;quot;,&lt;br /&gt;
      &amp;quot;  \\  |\&amp;quot;-\&amp;quot;`    |    \n&amp;quot;,&lt;br /&gt;
      &amp;quot;     || /=\\\\  |     \n&amp;quot;,&lt;br /&gt;
      &amp;quot;     \&amp;quot;&amp;#039;\&amp;quot;  &amp;#039;\&amp;quot;\&amp;quot;\&amp;quot;&amp;#039;&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To get access to this function we can locally load the package into memory (a weaker install than calling &amp;lt;code&amp;gt;library()&amp;lt;/code&amp;gt;) by running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;devtools::load_all()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note that &amp;lt;code&amp;gt;load_all()&amp;lt;/code&amp;gt; can be called over and over if you keep updating your function files and will re-load the newest verion of all your functions.&lt;br /&gt;
&lt;br /&gt;
==== Additional notes ====&lt;br /&gt;
&lt;br /&gt;
Unlike writing code in an &amp;lt;code&amp;gt;.Rmd&amp;lt;/code&amp;gt; or a &amp;lt;code&amp;gt;.R&amp;lt;/code&amp;gt; file, we deal with library dependencies slightly differently. If you know functions need tools from a certain library we put that library in the &amp;lt;code&amp;gt;Imports:&amp;lt;/code&amp;gt; section of your &amp;lt;code&amp;gt;DESCRIPTION&amp;lt;/code&amp;gt; file. Additional to use functions from outside libraries in our functions we have to write them like &amp;lt;code&amp;gt;package_name::function_name&amp;lt;/code&amp;gt;. For example in our function &amp;lt;code&amp;gt;call_scotty_demo&amp;lt;/code&amp;gt; if we wanted to use &amp;lt;code&amp;gt;stringr&amp;lt;/code&amp;gt;’s &amp;lt;code&amp;gt;str_sub&amp;lt;/code&amp;gt; function we’d have to have our code look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;call_scotty_demo &amp;lt;- function(your_name) {&lt;br /&gt;
  if (nchar(your_name) &amp;gt; 30){&lt;br /&gt;
    warning(&amp;quot;your name is beyond 30 characters, and has been truncated&amp;quot;)&lt;br /&gt;
    your_name &amp;lt;- stringr::str_sub(your_name, 1, 30)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  name_length &amp;lt;- nchar(your_name)&lt;br /&gt;
&lt;br /&gt;
  # Hiiiii&lt;br /&gt;
  cat(paste(&amp;quot;\n&amp;quot;,&lt;br /&gt;
    paste0(c(&amp;quot;&amp;quot;, rep(&amp;quot;-&amp;quot;, name_length + 8), &amp;quot;\n&amp;quot;), collapse = &amp;quot;&amp;quot;),&lt;br /&gt;
    paste0(c(&amp;quot;| Hi &amp;quot;, your_name, &amp;quot;! | \n&amp;quot;), collapse=&amp;quot;&amp;quot;),&lt;br /&gt;
    paste0(c(&amp;quot;|   &amp;quot;, rep(&amp;quot;-&amp;quot;, name_length + 4), &amp;quot;\n&amp;quot;), collapse = &amp;quot;&amp;quot;),&lt;br /&gt;
    paste0(c(&amp;quot;| /\n&amp;quot;)))&lt;br /&gt;
  )&lt;br /&gt;
&lt;br /&gt;
  # from Scotty.&lt;br /&gt;
  cat(paste0(&lt;br /&gt;
      &amp;quot; |/  |\\_/|          \n&amp;quot;,&lt;br /&gt;
      &amp;quot; |   |q p|   /}      \n&amp;quot;,&lt;br /&gt;
      &amp;quot; |   ( 0 )\&amp;quot;\&amp;quot;\&amp;quot;\\   \n&amp;quot;,&lt;br /&gt;
      &amp;quot;  \\  |\&amp;quot;-\&amp;quot;`    |    \n&amp;quot;,&lt;br /&gt;
      &amp;quot;     || /=\\\\  |     \n&amp;quot;,&lt;br /&gt;
      &amp;quot;     \&amp;quot;&amp;#039;\&amp;quot;  &amp;#039;\&amp;quot;\&amp;quot;\&amp;quot;&amp;#039;&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and our &amp;lt;code&amp;gt;DESCRIPTION&amp;lt;/code&amp;gt; file would need lines like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;Imports:&lt;br /&gt;
    stringr&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Step 3: Documenting your functions ===&lt;br /&gt;
&lt;br /&gt;
With &amp;lt;code&amp;gt;devtools&amp;lt;/code&amp;gt; and a package it’s actually really easy to create local documentation for your own functions so that &amp;lt;code&amp;gt;?function_name&amp;lt;/code&amp;gt; pops up documentation in the same way &amp;lt;code&amp;gt;?sum&amp;lt;/code&amp;gt; does in Rstudio.&lt;br /&gt;
&lt;br /&gt;
The easiest way to document your code is using &amp;lt;code&amp;gt;Roxygen2&amp;lt;/code&amp;gt;’s helper tools. To start, make sure you’ve downloaded the package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;install.packages(&amp;quot;roxygen2&amp;quot;)&lt;br /&gt;
library(roxygen2)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Then at the first line of a function you’ve written (when you’re in Rstudio) use the short-cut &amp;lt;code&amp;gt;Command + Option + Shift + R&amp;lt;/code&amp;gt; (Mac) or &amp;lt;code&amp;gt;Ctrl+ Alt + Shift + R&amp;lt;/code&amp;gt; (Windows), this will auto-generate a documentation structure to fill in.&lt;br /&gt;
&lt;br /&gt;
For example, if we had the function from above used the shortcut, we would then have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;#&amp;#039; Title&lt;br /&gt;
#&amp;#039;&lt;br /&gt;
#&amp;#039; @param your_name&lt;br /&gt;
#&amp;#039;&lt;br /&gt;
#&amp;#039; @return&lt;br /&gt;
#&amp;#039; @export&lt;br /&gt;
#&amp;#039;&lt;br /&gt;
#&amp;#039; @examples&lt;br /&gt;
call_scotty_demo &amp;lt;- function(your_name) {&lt;br /&gt;
  ...&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which we could fill in with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;#&amp;#039; Meet Scotty, the Scottie Dog&lt;br /&gt;
#&amp;#039;&lt;br /&gt;
#&amp;#039; @param your_name string of your name (max length 30 characters)&lt;br /&gt;
#&amp;#039;&lt;br /&gt;
#&amp;#039; @return NULL. Though scotty appears on your screen and says Hi to you.&lt;br /&gt;
#&amp;#039; @export&lt;br /&gt;
#&amp;#039;&lt;br /&gt;
#&amp;#039; @examples&lt;br /&gt;
#&amp;#039; call_scotty_demo(&amp;quot;Andrew Carnegie&amp;quot;)&lt;br /&gt;
call_scotty_demo &amp;lt;- function(your_name) {&lt;br /&gt;
  ...&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The basic structure of the documentation is decently straightforward (you can remove &amp;lt;code&amp;gt;@export&amp;lt;/code&amp;gt; if you don’t want the function to export, and you can remove &amp;lt;code&amp;gt;@examples&amp;lt;/code&amp;gt; if you don’t have any examples), but detailed guidance, documentation [https://r-pkgs.org/man.html?q=roxygen#man here] can be super helpful (with information on linking functions and other packages, adding math equations, code text, etc.)&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Now&amp;#039;&amp;#039;&amp;#039; to actually create a documentation file, we run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;devtools::document()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The first time we do this we’ll create &amp;lt;code&amp;gt;man/&amp;lt;/code&amp;gt; folder if one doesn’t always exist and also create / update a corresponding file named &amp;lt;code&amp;gt;man/call_scotty_demo.Rd&amp;lt;/code&amp;gt; file that R uses to generate documentation. Additionally, the &amp;lt;code&amp;gt;document()&amp;lt;/code&amp;gt; function also updates the &amp;lt;code&amp;gt;NAMESPACE&amp;lt;/code&amp;gt; file so when you load your functions you get the desired documenation (need to have &amp;lt;code&amp;gt;@export&amp;lt;/code&amp;gt; in the docstring).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;man/call_scotty_demo.Rd&amp;lt;/code&amp;gt; document file looks like the following. Notice how it says “do not edit by hand”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;{r eval=F} % Generated by roxygen2: do not edit by hand % Please edit documentation in R/welcome.R \name{call_scotty_demo} \alias{call_scotty_demo} \title{Meet Scotty, the Scottie Dog} \usage{ call_scotty_demo(your_name) } \arguments{ \item{your_name}{string of your name (max length 30 characters)} } \value{ \code{NULL}. Though scotty appears on your screen and says Hi to you. } \description{ Meet Scotty, the Scottie Dog } \examples{ call_scotty_demo(&amp;amp;quot;Andrew Carnegie&amp;amp;quot;) }&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To actually view your documentation files we need to re-load the package and then use the standard &amp;lt;code&amp;gt;?&amp;lt;/code&amp;gt; to get the help file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;devtools::load_all()&lt;br /&gt;
?call_scotty_demo&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:call_scotty_demo_doc.png|frameless|600px|alt=example of help file|example of help file]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4: Testing ===&lt;br /&gt;
&lt;br /&gt;
Testing is critical to making sure your functions do what you expect. The easiest way to get started with testing is the &amp;lt;code&amp;gt;testthat&amp;lt;/code&amp;gt; package, which also integrates with &amp;lt;code&amp;gt;devtools&amp;lt;/code&amp;gt;. To start testing using &amp;lt;code&amp;gt;testthat&amp;lt;/code&amp;gt; in your new R package do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;{r eval = F} install.packages(&amp;amp;quot;testthat&amp;amp;quot;) usethis::use_testthat()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will set up the &amp;lt;code&amp;gt;tests/testthat&amp;lt;/code&amp;gt; directory where we can store tests.&lt;br /&gt;
&lt;br /&gt;
==== What’s the philosophy behind &amp;lt;code&amp;gt;testthat&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;testthat&amp;lt;/code&amp;gt; functionality can be see as tools to do a range of needs, from low level testing all the way up to overall testing of all functions in a package.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the low level, &amp;lt;code&amp;gt;testthat&amp;lt;/code&amp;gt; provides functions to test your &amp;#039;&amp;#039;&amp;#039;expectations&amp;#039;&amp;#039;&amp;#039;. The most fundamental unit of testing is this low level. &amp;lt;code&amp;gt;testthat&amp;lt;/code&amp;gt;’s &amp;lt;code&amp;gt;expect_...&amp;lt;/code&amp;gt; functions provide the building blocks for testing. They describe what result is expected for your various computations and we can use these to make sure our functions are giving the expected output. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;library(testthat)&lt;br /&gt;
expect_equal(1, 1)&lt;br /&gt;
expect_equal(1, 2)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Returns:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;## Error: 1 not equal to 2.&lt;br /&gt;
## 1/1 mismatches&lt;br /&gt;
## [1] 1 - 2 == -1&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;#039;&amp;#039;&amp;#039;Grouping expectations&amp;#039;&amp;#039;&amp;#039; is the next level. We can group a set of expectations to examine more complex functionality with the wrapper &amp;lt;code&amp;gt;test_that&amp;lt;/code&amp;gt; which takes in a string describing what you’re examining, and then a set of &amp;lt;code&amp;gt;expect_...&amp;lt;/code&amp;gt;s that are wrapping in &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;test_that(paste(&amp;quot;calling scotty works well (returns null&amp;quot;,&lt;br /&gt;
                 &amp;quot;and provides warning nchar &amp;gt; 30)&amp;quot;), {&lt;br /&gt;
  expect_equal(call_scotty_demo(&amp;quot;Oski Bear&amp;quot;), NULL)&lt;br /&gt;
  expect_warning(call_scotty_demo(&amp;quot;Oski Bear, your a wonderful, but slightly creepy Berkeley Bear&amp;quot;))&lt;br /&gt;
  expect_equal(1, 2)&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Returns:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;##&lt;br /&gt;
##  -----------------&lt;br /&gt;
##  | Hi Oski Bear! |&lt;br /&gt;
##  |   -------------&lt;br /&gt;
##  | /&lt;br /&gt;
##  |/  |\_/|&lt;br /&gt;
##  |   |q p|   /}&lt;br /&gt;
##  |   ( 0 )&amp;quot;&amp;quot;&amp;quot;\&lt;br /&gt;
##   \  |&amp;quot;-&amp;quot;`    |&lt;br /&gt;
##      || /=\\  |&lt;br /&gt;
##      &amp;quot;&amp;#039;&amp;quot;  &amp;#039;&amp;quot;&amp;quot;&amp;quot;&amp;#039;&lt;br /&gt;
##  --------------------------------------&lt;br /&gt;
##  | Hi Oski Bear, your a wonderful, b! |&lt;br /&gt;
##  |   ----------------------------------&lt;br /&gt;
##  | /&lt;br /&gt;
##  |/  |\_/|&lt;br /&gt;
##  |   |q p|   /}&lt;br /&gt;
##  |   ( 0 )&amp;quot;&amp;quot;&amp;quot;\&lt;br /&gt;
##   \  |&amp;quot;-&amp;quot;`    |&lt;br /&gt;
##      || /=\\  |&lt;br /&gt;
##      &amp;quot;&amp;#039;&amp;quot;  &amp;#039;&amp;quot;&amp;quot;&amp;quot;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
## Error: Test failed: &amp;#039;calling scotty works well (returns null and provides warning nchar &amp;gt; 30)&amp;#039;&lt;br /&gt;
## * 1 not equal to 2.&lt;br /&gt;
## 1/1 mismatches&lt;br /&gt;
## [1] 1 - 2 == -1&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;#039;&amp;#039;&amp;#039;A set of grouped tests&amp;#039;&amp;#039;&amp;#039; in single file. When building a package your functions will likely like in different &amp;lt;code&amp;gt;.R&amp;lt;/code&amp;gt; files in the &amp;lt;code&amp;gt;R/&amp;lt;/code&amp;gt; folder. To mirror this structure we put of our tests associated with a single &amp;lt;code&amp;gt;.R&amp;lt;/code&amp;gt; file into 1 test file. These files sit in the &amp;lt;code&amp;gt;tests/testthat/&amp;lt;/code&amp;gt; folder and must start with &amp;lt;code&amp;gt;test&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;devtools&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;usethis&amp;lt;/code&amp;gt; provide a way to create these test in an automated fashion. For example, if we wanted to create a file &amp;lt;code&amp;gt;tests/testthat/test-welcome.R&amp;lt;/code&amp;gt;, we could call&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;usethis::use_test(&amp;quot;welcome&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which provides the message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;✔ Setting active project to &amp;#039;./tartan&amp;#039;&lt;br /&gt;
✔ Adding &amp;#039;testthat&amp;#039; to Suggests field in DESCRIPTION&lt;br /&gt;
✔ Creating &amp;#039;tests/testthat/&amp;#039;&lt;br /&gt;
✔ Writing &amp;#039;tests/testthat.R&amp;#039;&lt;br /&gt;
✔ Writing &amp;#039;tests/testthat/test-welcome.R&amp;#039;&lt;br /&gt;
● Modify &amp;#039;tests/testthat/test-welcome.R&amp;#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In these larger files (relative to group functions) we include group expectations as well as context information for the overall file using the &amp;lt;code&amp;gt;context()&amp;lt;/code&amp;gt; function. And example can be see below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;context(&amp;quot;test welcome from scotty&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
test_that(paste(&amp;quot;calling scotty works well (returns null&amp;quot;,&lt;br /&gt;
                 &amp;quot;and provides warning nchar &amp;gt; 30)&amp;quot;), {&lt;br /&gt;
  expect_equal(call_scotty_demo(&amp;quot;Oski Bear&amp;quot;), NULL)&lt;br /&gt;
  expect_warning(call_scotty_demo(&amp;quot;Oski Bear, your a wonderful, but slightly creepy Berkeley Bear&amp;quot;))&lt;br /&gt;
  expect_equal(1, 2)&lt;br /&gt;
})&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Once you have a test file in your package all you need to do is run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;devtools::test()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and R will run all your associated test, and will return output like seen in the following image:&lt;br /&gt;
&lt;br /&gt;
[[File:devtool_test_example.png|frameless|600px|alt=output of testthat|output of testthat]]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5. Checking the full package ===&lt;br /&gt;
&lt;br /&gt;
To understanding if your overall package is clean and able to be shared we can run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;devtools::check()&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This checks all your dependencies, syntax, and more that may have slipped through the cracks. Often times this is only necessary when you’re looking to share your package with others, but is a good step to include so you don’t have to change a lot of things right before sharing.&lt;br /&gt;
&lt;br /&gt;
=== Step 6: Syncronizing with Github ===&lt;br /&gt;
&lt;br /&gt;
As always, once you’ve completed a clean block of code you should push it to Github. When your code is on github other folks can download the package in a similar fashion to the standard &amp;lt;code&amp;gt;install.packages(...)&amp;lt;/code&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
For example, to install the R package we just made we could use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;{r eval = T, message=F, warning=F} devtools::install_github(repo = &amp;amp;quot;benjaminleroy/tartan&amp;amp;quot;,                          force = F) # so making the sides does do it a ton of times library(tartan) #?call_scotty_demo call_scotty_demo(&amp;amp;quot;Big Bird&amp;amp;quot;)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 7: And beyond! ===&lt;br /&gt;
&lt;br /&gt;
In the above example we still didn’t cover a lot of things, including:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Including data in your package (that can be [http://r-pkgs.had.co.nz/data.html documented] too)&lt;br /&gt;
&amp;lt;code&amp;gt;r     # suppose that I have a tarans dataset that I created - than I can save it this way     usethis::use_data(tartans)     # and document at     usethis::use_r(&amp;amp;quot;data&amp;amp;quot;)&amp;lt;/code&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Vignettes (long form documentation, knitr) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Compiled code (C, C++, Fortran…) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Creating a CRAN ready package &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; See [https://usethis.r-lib.org/reference/index.html &amp;lt;code&amp;gt;usethis&amp;lt;/code&amp;gt;] to see all the package development steps that &amp;lt;code&amp;gt;usethis&amp;lt;/code&amp;gt; automates. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skipper</name></author>
	</entry>
</feed>