Assignment 5: Packages
To do yourself
Packages
Writing R packages lecture slides by Daniel Sjoberg. GitHub source
How to create an R package lecture slides by Irene Steves, Mitchell Maier. GitHub source
Short notes by Karl Broman: How-to package functions, Transform repeated code into functions, R package primer, and Package tutorial by Hillary Parker
R packages by Brooke Anderson
R packages book by Hadley Wickham
Package Development tutorial for useR! 2019 Toulouse, by Jenny Bryant, slides, exercises
GitHub
New to Git and GitHub? This Essential Beginners Guide is for you
Resources to learn Git - Git handbook, cheatsheets, interactive tutorials
Git and GitHub guide, by Karl Broman
Blischak, John D., Emily R. Davenport, and Greg Wilson. “A Quick Introduction to Version Control with Git and GitHub.” Edited by Francis Ouellette. PLOS Computational Biology 12, no. 1 (January 19, 2016) - An excellent explanation of Git and GitHub. Definitions (Box 1), tutorial
Bryan, Jennifer. “Excuse Me, Do You Have a Moment to Talk about Version Control?”
Happy Git and GitHub for the useR by Jenny Bryan
Git and GitHub for Beginners - 1-hour video course by Gwen Faraday
To submit on Canvas
Functions
Create an R package that includes two functions to perform the following tasks. All of your functions should be written clearly, with commented code, readable spacing, and be as non-repetitive as possible. Document your functions using Roxygen2 syntax.
- The Pythagorean theorem states that the square of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the other two side: \(c^2=a^2+b^2\). Write a function that, given the lengths of two sides of the triangle, calculates the length of the third side.
Note: This function should be flexible - that is, the function works if I give it values for \(a\) and \(b\), or \(b\) and \(c\), or \(a\) and \(c\). If the user only provides the length of one side, the function should throw an error. Likewise, if the user provides the lengths of all three sides, the function should throw an error. If the user provides any values other than numeric values, the function should throw an error.
- Write your own trimmed mean function that calculates the mean of a numeric vector \(x\), ignoring the \(s\) smallest and \(l\) largest values (this is a trimmed mean). For example, if \(x=c(1,7,3,2,5,0.5,9,10)\), \(s=1\), and \(l=2\), your function would return the mean of \(c(1,7,3,2,5)\) (this is \(x\) with the \(1\) smallest value and the \(2\) largest values removed). Note: Your function should check if \(x\) has at least \(s+l+1\) values. If not, return some error message with stop().
GitHub
Install Git, and create a Github account. Update your Github profile to include some relevant information about yourself, such as your program and/or interests. Submit the link to your profile.
In command line, go to the hidden
.git
folder, list all files/folders. Describe and submit your observations.Create a repository out of the R package you created in Homework 6. Add all your files, push to GitHub. Make sure your package can be installed from GitHub (Hint:
devtools::install_github()
). Submit the link to your repository.