<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/mit-step-by-step-instructions-for-creating-your-own-r-package/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://feedproxy.google.com/~r/DataRValue/~3/EDuTH0hjfok/mit-step-by-step-instructions-for.html"> Data R Value</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><span><span lang="en"><span>We will mention the steps to create your own R package using RStudio and we will provide the link to download the complete MIT guide:”<i>Instructions for Creating Your Own R Package</i>“, In Song kim, Phil Martin, Nina McMurry. February 23, 2016 .</span></span></span></p>
<p><span><span lang="en"><span>1. Start by opening a new .R file. Make sure your default directory is clear by typing rm(list= ls()). Check to see that it is empty using ls() (you should see character(0)).</span></span></span><br><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span>2. Write the code for your functions in this .R file. You can create one file with all of your functions or create separate files for each function. Save these files somewhere where you can easily find them.</span></span></span><br><span><span lang="en"><span><br></span></span></span>
<div><a target="_blank" rel="nofollow" href="https://i2.wp.com/1.bp.blogspot.com/-Tttdl8liWCM/WQ4BDtYPdXI/AAAAAAAAC4Y/5NoAWvlzwxo6I2PBrR85EPDkl7CqOnYOgCLcB/s1600/pack_1.png?ssl=1"><img src="https://i2.wp.com/1.bp.blogspot.com/-Tttdl8liWCM/WQ4BDtYPdXI/AAAAAAAAC4Y/5NoAWvlzwxo6I2PBrR85EPDkl7CqOnYOgCLcB/s400/pack_1.png?resize=400%2C217&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span>3. Install the ‘devtools’ package (install.packages(‘devtools’)).</span></span></span><br><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span>4. Open a new project in RStudio. Go to the ‘File’ menu and click on ‘New Project.’ Then select ‘New Directory,’ and ‘R Package’ to create a new R package.</span></span></span><br><span><span lang="en"><span><br></span></span></span>
<div><a target="_blank" rel="nofollow" href="https://i1.wp.com/2.bp.blogspot.com/-PwA-XnGUWds/WQ4BI6urhvI/AAAAAAAAC4c/hxgYAtpNPpktS5EFitEW5JvlqS7D4z5gQCLcB/s1600/pack_2.png?ssl=1"><img src="https://i2.wp.com/2.bp.blogspot.com/-PwA-XnGUWds/WQ4BI6urhvI/AAAAAAAAC4c/hxgYAtpNPpktS5EFitEW5JvlqS7D4z5gQCLcB/s400/pack_2.png?resize=400%2C217&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span>5. Type the name of your package, then upload the .R file you created in step 1 under ‘Create package based on source files’. Click ‘Create project.’</span></span></span><br><span><span lang="en"><span><br></span></span></span>
<div><a target="_blank" rel="nofollow" href="https://i1.wp.com/3.bp.blogspot.com/-UokOZUCxhuc/WQ4BOaMFo8I/AAAAAAAAC4g/JN5NZl0SWpc_XIoMM5mMdlbt7jxv9nOlACLcB/s1600/pack_3.png?ssl=1"><img src="https://i2.wp.com/3.bp.blogspot.com/-UokOZUCxhuc/WQ4BOaMFo8I/AAAAAAAAC4g/JN5NZl0SWpc_XIoMM5mMdlbt7jxv9nOlACLcB/s400/pack_3.png?resize=400%2C212&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span>6. On the lower right hand side of your screen, you should see a file directory. The ‘R’ folder contains the code for your functions. The ‘man’ folder will contain the help files for each function in your package. Depending on your version of RStudio, the help files may have been generated automatically as .Rd or “R documentation” files when you created your package.<br>If the ‘man’ folder already contains .Rd files, open each file, add a title under the ‘title’ heading, and save (if not, see step 7). You can go back and edit the content later, but you will need to add a title to each .Rd file in order to compile your package.</span></span></span><br><span><span lang="en"><span><br></span></span></span>
<div><a target="_blank" rel="nofollow" href="https://i1.wp.com/4.bp.blogspot.com/-46mOa2bu-fk/WQ4BT8-_w1I/AAAAAAAAC4k/WTOfyBFKixgT3Ai4w5AGsP7y80Bq2k-jgCLcB/s1600/pack_4.png?ssl=1"><img src="https://i1.wp.com/4.bp.blogspot.com/-46mOa2bu-fk/WQ4BT8-_w1I/AAAAAAAAC4k/WTOfyBFKixgT3Ai4w5AGsP7y80Bq2k-jgCLcB/s400/pack_4.png?resize=400%2C215&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span>7. If your ‘man’ file is empty, you will have to manually create a .Rd file for each function. To do this, go to File > New File > R Documentation, enter the title of the function and select ‘Function’ under the ‘Rd template’ menu. Edit your new file to include something in the ‘title’ field (again, you may make other edits now or go back and make edits later, but your package will not compile if the ‘title’ field is empty). Save each .Rd file in the ‘man’ folder.<br>NOTE: You will need to complete this step if you add more functions to your package at a later point, even if RStudio automatically generated R documentation files when you initially created the package.</span></span></span><br><span><span lang="en"><span><br></span></span></span>
<div><a target="_blank" rel="nofollow" href="https://i2.wp.com/3.bp.blogspot.com/-_R4hWiVrxwU/WQ4BZfGueEI/AAAAAAAAC4o/sW4SaASBaaEEdocQJvBtP-hF7CtXXOHEQCLcB/s1600/pack_5.png?ssl=1"><img src="https://i2.wp.com/3.bp.blogspot.com/-_R4hWiVrxwU/WQ4BZfGueEI/AAAAAAAAC4o/sW4SaASBaaEEdocQJvBtP-hF7CtXXOHEQCLcB/s400/pack_5.png?resize=400%2C215&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span>8. Now you are ready to compile your package. Go to ‘Build’ on the top toolbar and select ‘Build and Reload’ (note you can also use the keyboard shortcut Ctrl+Shift+B). If this works, your package will automatically load and you will see library(mynewpackage) at the bottom of your console. Test your functions to make sure they work.</span></span></span><br><span><span lang="en"><span><br></span></span></span>
<div><a target="_blank" rel="nofollow" href="https://i1.wp.com/3.bp.blogspot.com/-rcG2qyeF-wo/WQ4BfX5hQ0I/AAAAAAAAC4s/c1-rp4iMdfQAGfypS20QGVPCcVJcyBbhQCLcB/s1600/pack_6.png?ssl=1"><img src="https://i2.wp.com/3.bp.blogspot.com/-rcG2qyeF-wo/WQ4BfX5hQ0I/AAAAAAAAC4s/c1-rp4iMdfQAGfypS20QGVPCcVJcyBbhQCLcB/s400/pack_6.png?resize=400%2C213&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span>9. Go back and edit the documentation (the help file) for each function. Open each .Rd file, add a brief description of the package, define its arguments and, if applicable, values, and include at least one example. Then, re-compile your package and test out your documentation in the R console (?myfun). NOTE: You will need to re-compile (repeating step 8) each time you make changes to your functions or documentation.</span></span></span><br><span><span lang="en"><span><br></span></span></span>
<div><a target="_blank" rel="nofollow" href="https://i2.wp.com/1.bp.blogspot.com/-kpqUhsyj5lM/WQ4Bky0GelI/AAAAAAAAC4w/egDUwzcpBb0EpL923Weh7X-keJlMm3DSQCLcB/s1600/pack_7.png?ssl=1"><img src="https://i0.wp.com/1.bp.blogspot.com/-kpqUhsyj5lM/WQ4Bky0GelI/AAAAAAAAC4w/egDUwzcpBb0EpL923Weh7X-keJlMm3DSQCLcB/s400/pack_7.png?resize=400%2C215&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span>10. Once you have finished creating your functions and documentation, compiled your package, and double checked that the functions and help files work, copy the entire folder containing your package to the Dropbox folder with your name on it.</span></span></span><br><span><span lang="en"><span><br></span></span></span><br><span><span lang="en"><span>Download the complete guide at:</span></span></span><br><span><span lang="en"><span><span><a target="_blank" rel="nofollow" href="https://github.com/pakinja/Data-R-Value/tree/master/R_Package_Instructions">https://github.com/pakinja/Data-R-Value</a></span></span></span></span><br><span><span lang="en"><span><br></span></span></span><img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/DataRValue/~4/EDuTH0hjfok"></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://feedproxy.google.com/~r/DataRValue/~3/EDuTH0hjfok/mit-step-by-step-instructions-for.html"> Data R Value</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/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/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/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/X6IMq5koxwA"></a></div>