Assignment 5: Packages

Due by 11:59 PM on Friday, December 9, 2022

To do yourself

Packages

GitHub

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.