R/specific_ag_problems.R

Defines functions make_hourly_pred make_web_pred make_weather_pred make_ci_pred make_pred

Documented in make_ci_pred make_hourly_pred make_pred make_weather_pred make_web_pred

#' Make Hourly Predictions
#'
#' Creates a valid autograde file for hourly  project
#' @param hourly A \code{numeric} vector with 24 values.
#' @return A \code{.csv} with observations on each new line written to the working
#' directory given by \code{getwd()}.
#' @export
#' @examples
#' \dontrun{
#' # Make some predictions
#' hourly = 1:24
#' make_hourly_pred(hourly)
#' }
make_hourly_pred = function(hourly){

  stopifnot(length(hourly) == 24L)

  message("Creating a 24 x 1 matrix with order:")
  message("00:00, 01:00, ..., 23:00")

  yhat = matrix(c(hourly), nrow = 24, ncol = 1)

  now = Sys.time()
  # Remove file extension
  file.name = paste0("hourly_pred_", format(now, format="%Y_%m_%d_%I_%M_%S_%p"))

  write.table(yhat, file = paste0(file.name,".csv"), sep = ",",  row.names = F, col.names = F)
  message("Wrote prediciton file ", file.name,".csv to directory ", getwd(), ".")
  message(">> Remember to submit the file to the autograder! <<")
}

#' Make Web Predictions
#'
#' Creates a valid autograde file for web analytics project
#' @param Rcpp,ggplot2,stringr,dplyr A single \code{numeric} value for each of the parameters.
#' @return A \code{.csv} with observations on each new line written to the working
#' directory given by \code{getwd()}.
#' @export
#' @examples
#' \dontrun{
#' # Make some predictions
#' Rcpp = 1
#' ggplot2 = 2
#' stringr = 3
#' dplyr = 4
#'
#' make_web_pred(Rcpp, ggplot2, stringr, dplyr)
#' }
make_web_pred = function(Rcpp, ggplot2, stringr, dplyr){

    a = list(Rcpp, ggplot2, stringr, dplyr)

    stopifnot(all(sapply(a, length) == 1L))

    message("Creating a 1 x 4 matrix with order:")
    message("Rcpp, ggplot2, stringer, dplyr...")

    yhat = matrix(c(Rcpp,ggplot2,stringr,dplyr), nrow = 1, ncol = 4)

    now = Sys.time()
    # Remove file extension
    file.name = paste0("web_pred_", format(now, format="%Y_%m_%d_%I_%M_%S_%p"))

    write.table(yhat, file = paste0(file.name,".csv"), sep = ",",  row.names = F, col.names = F)
    message("Wrote prediciton file ", file.name,".csv to directory ", getwd(), ".")
    message(">> Remember to submit the file to the autograder! <<")
}


#' Make Weather Predictions
#'
#' Creates a valid autograde file for Weather Project
#' @param high,low,mean A single \code{numeric} value for each of the parameters.
#' @return A \code{.csv} with observations on each new line written to the working
#' directory given by \code{getwd()}.
#' @export
#' @examples
#' \dontrun{
#' # Make some predictions
#' make_weather_pred(high = 1, low = 2, mean = 3)
#' }
make_weather_pred = function(high, low, mean){

    a = list(high, low, mean)

    stopifnot(all(sapply(a, length) == 1L))

    message("Creating a 1 x 3 matrix with order:")
    message("high, low, mean...")

    yhat = matrix(c(high, low, mean), nrow = 1, ncol = 3)

    now = Sys.time()
    # Remove file extension
    file.name = paste0("weather_pred_", format(now, format="%Y_%m_%d_%I_%M_%S_%p"))

    write.table(yhat, file = paste0(file.name,".csv"), sep = ",",  row.names = F, col.names = F)
    message("Wrote prediciton file ", file.name,".csv to directory ", getwd(), ".")
    message(">> Remember to submit the file to the autograder! <<")
}


#' Make CI Predictions
#'
#' Creates a valid autograde file for CI Mu Problem
#' @param ci90,ci95,ci99 Two \code{numeric} values for each of the parameters.
#' @return A \code{.csv} with observations on each new line written to the working
#' directory given by \code{getwd()}.
#' @export
#' @examples
#' \dontrun{
#' # Make CI AG File
#' make_ci_pred(ci90 = c(-1,1), ci95 = c(-1.5,1.5), ci99 = c(-2.5,2.5))
#' }
make_ci_pred = function(ci90, ci95, ci99){

    a = list(ci90, ci95, ci99)

    stopifnot(all(sapply(a, length) == 2L))

    message("Creating a 2 x 3 matrix with order:")
    message("ci90, ci95, ci99...")

    yhat = matrix(c(ci90, ci95, ci99), nrow = 2, ncol = 3, byrow = FALSE)

    now = Sys.time()
    # Remove file extension
    file.name = paste0("ci_pred_", format(now, format="%Y_%m_%d_%I_%M_%S_%p"))

    write.table(yhat, file = paste0(file.name,".csv"), sep = ",",  row.names = F, col.names = F)
    message("Wrote prediciton file ", file.name,".csv to directory ", getwd(), ".")
    message(">> Remember to submit the file to the autograder! <<")
}


#' Make Predictions
#'
#' Creates a valid autograde file for the prediction problems
#' @param x Ten \code{numeric} values.
#' @return A \code{.csv} with observations on each new line written to the working
#' directory given by \code{getwd()}.
#' @export
#' @examples
#' \dontrun{
#' # Make some predictions
#' make_pred(x = 1:10)
#' }
make_pred = function(x){

    stopifnot(length(x) == 10L)

    message("Creating a 10 x 1 matrix with order:")
    message("t = n + 1, t = n + 2, ... , t = n + 10")

    yhat = matrix(x, nrow = 10, ncol = 1, byrow = TRUE)

    now = Sys.time()
    # Remove file extension
    file.name = paste0("forecast_pred_", format(now, format="%Y_%m_%d_%I_%M_%S_%p"))

    write.table(yhat, file = paste0(file.name,".csv"), sep = ",",  row.names = F, col.names = F)
    message("Wrote prediciton file ", file.name,".csv to directory ", getwd(), ".")
    message(">> Remember to submit the file to the autograder! <<")
}
coatless/autograde documentation built on May 13, 2019, 8:45 p.m.