```{r, include=FALSE}
# Do not edit this code chunk
knitr::opts_chunk$set(echo = TRUE, message=FALSE, warning = FALSE)
```

# Datasets

We will use the `babynames` dataset.

The `babynames` dataset contains for each year from 1880 to 2017 the number of children of each sex given each name (as recorded by the US Social Security Administration). All names with more than 5 uses are given.

Write these functions as a normal pipe line, then go back and make them into functions. 

# User-defined Functions

```{r}
library(tidyverse)
library(babynames)

```

## Exercise 1

Write a function called `count_name` that, when given a name (e.g.,`Angelica`, `Ezekiel`, or `Riley`) as an argument, returns the total number of births by year from the `babynames` data frame in the `babynames` package that match that name. An outline has been provided.

```{r}
# Write your code below
count_name <- function(data = babynames , name_arg = "Nicholas"){
  if(is.element(name_arg, babynames$name)) { # This checks if the name is in the babyname's name columnm.
    # Do some wrangling here
      
  }
  else{
    stop("Name not found")
  }
}


```


## Bonus!

The `count_name` function should return one row per year that matches (and generate an error message if there are no matches). Run the function once with the argument `Ezekiel` and once with `Ezze`.

```{r}


```

## Exercise 2

Write a function called `grab_name` that, when given a name and a year as an argument, returns the rows from the `babynames` data frame in the `babynames` package that match that name for that year (and returns an error if that name and year combination does not match any rows). Run the function once with the arguments `Ezekiel` and `1883` and once with `Ezze` and `1883`. 

Challenge: Add an `else if` after your `if` and before your `else` to catch an error if people choose a year less than 1880 (outside of the range of our data). 

```{r}
# Write your code below

library(tidyverse)
library(babynames)

grab_name <- function(data = babynames, name_arg , year_arg ){

  
}
grab_name( name_arg = "Ezekiel", year_arg = 1883)

```

# Writing Functions to Create Plots

## Exercise 3

Write a function called `count_name_graph()` that will use the function `countname()` to make a line graph that plots the year and the number of babies in a given year. The graph's title should be "the "Babies Named (name of baby)" . The `paste()` function in r will help with your title, use it to put two strings together. Label your x and y axes. 

```{r}
# Write your code below

```

# Generalizing Functions for Data Frames

Write a function that adds up the total number of children born with a given name in the US since 1880. 

```{r}

```

