Cheat function

question_2 <- function() {
  schiphol_temp <- read.csv(
    url(
      "https://raw.githubusercontent.com/hannesrosenbusch/schiphol_class/master/schiphol_data.csv"
    )
  )
  
  plot(schiphol_temp$DATE, schiphol_temp$TMIN)
}

question_6 <- function() {
  install.packages("dplyr")
  library(dplyr)
  
  chicks_data <- ChickWeight
  my_chicks <-
    chicks_data[chicks_data$Chick %in% c(1, 20, 5, 40, 19), ] # Select chickens
  my_chicks$Chick <-
    factor(my_chicks$Chick, c(1, 20, 5, 40, 19)) # Set order
  max_weight <-
    aggregate(weight ~ Chick, data = my_chicks, max) # Select max
  
  chicks_plot <- ggplot(max_weight, aes(Chick, weight)) + geom_col()
  chicks_plot <- chicks_plot + xlab("chick") + ylab("max_weight")
  chicks_plot
}

question_11 <- function() {
  install.packages("cranlogs")
  library(cranlogs)
  install.packages("gganimate")
  library(gganimate)
  install.packages("gifski")
  library(gifski)
  
  file_renderer(dir = ".",
                prefix = "gganim_plot",
                overwrite = FALSE)
  
  ggplot_data <-
    cran_downloads(packages = "ggplot2", from = "2014-01-01")
  plotly_data <-
    cran_downloads(packages = "plotly", from = "2014-01-01")
  animated_data <- rbind(ggplot_data, plotly_data)
  
  animated_plot <-
    ggplot(animated_data,
           aes(date, count, group = package, color = package)) + geom_line()
  animated_plot <- animated_plot + transition_reveal(date)
  animated_plot <-
    animated_plot + ylab("Package Downloads") + ggtitle("Package popularity over time")
  animated_plot
  
  animate(animated_plot, renderer = gifski_renderer())
}

cheat <- function(question) {
  if (question == 2 | question == "3.1.2" | question == "Q3.1.2") {
    print(question_2)
  }
  else if (question == 6 |
           question == "3.1.6" | question == "Q3.1.6") {
    print(question_6)
  }
  else if (question == 11 |
           question == "3.1.11" | question == "Q3.1.11") {
    print(question_11)
  }
  else {
    print("Oops :0 No cheatsheet for this one. Time to study!")
  }
}