knitr::opts_chunk$set(echo = TRUE)
Load in common libraries used by this package.
library(ggplot2) library(tidyverse)
Now, we install my R package.
devtools::install_github("sydneyhemphill/R_Package_Hemphill")
Let us download some data for our package:
download.file("https://raw.githubusercontent.com/sydneyhemphill/R_package_Hemphill/master/data/Butterfly_data.csv" , destfile = "/cloud/project/data/butterfly_data.csv")
Statistical Test: This function is helpful because it takes out the chance of any mistakes while typing and will save time. The output of the data should be a summary of the linear model for your data.
library(HemphillRPackage) linear.model <- function(x,y,z){ model.fit<- lm(x ~ y, data = z) return(summary(model.fit)) }
For an example of this function in use:
library(HemphillRPackage) linear.model(butterfly.data$SpringTemp,butterfly.data$Year, butterfly.data)
Plot Function: This function is helpful because it creates basic plots, so you don't have to type out everything when comparing data or you need a lot of basic graphs for your reports. The output of the data should be a simple gg (scatter) plot.
library(HemphillRPackage) plot<- function(z, x, y){ product<- ggplot(z, aes(x=x, y = y)) + geom_point() return (product) }
An example of this function in use:
library(HemphillRPackage) plot(butterfly.data, butterfly.data$Year, butterfly.data$Day )
Clean Up Function: This function removes NAs from databases. Removing NAs can take a long time, especially with large databases, so this function takes all the work, and possibility of error, out by removing the NAs as the file is read in.
library(HemphillRPackage) no.na<- function(file = "/cloud/project/data/Butterfly_data.csv"){ butterfly<- read_csv(file) butterfly <- na.omit(butterfly) return(butterfly) }
An example of this function in action is:
library(HemphillRPackage) no.na("/cloud/project/data/Butterfly_data.csv")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.