#Haris Javed
#What the Variables mean
#df - takes a the babynames dataframe as argument
#gender - takes "M" for Males, and "F" for Females
#yr -  takes the year values from 1880 to 2017
#top_how_many - it gives us the names with the highest probability e.g. top 20 names based on probability 

bNames <- function(df, gender,yr, top_how_many){
  library(tidyverse)
  library(babynames)
  library(data.table)
  library(rlang)
  if (gender != "F" && gender != "M"){
    stop('You used Incorrect Gender Tag - Gender is required, and must be M for Male, and F for Female')
  }
  if (yr < 1880 || yr > 2017){
    stop('You used Incorrect Year - Year is required, and must be BETWEEN 1879 and 2018')
  }
  data.table(head(df %>% filter(sex == gender & year == yr) %>% group_by(name) %>% summarise(Total = sum(n), prop) %>% arrange(desc(Total)) %>% filter(Total > 300), top_how_many))
}