diff --git a/NAMESPACE b/NAMESPACE index b65a7e6b2..2833d8aca 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -44,10 +44,12 @@ S3method(prep,step_growth_rate) S3method(prep,step_lag_difference) S3method(prep,step_population_scaling) S3method(prep,step_training_window) -S3method(print,arx_clist) -S3method(print,arx_flist) +S3method(print,alist) +S3method(print,arx_class) +S3method(print,arx_fcast) +S3method(print,canned_epipred) S3method(print,epi_workflow) -S3method(print,flatline_alist) +S3method(print,flatline) S3method(print,frosting) S3method(print,layer_add_forecast_date) S3method(print,layer_add_target_date) @@ -92,13 +94,14 @@ export(add_layer) export(apply_frosting) export(arx_args_list) export(arx_class_args_list) +export(arx_class_epi_workflow) export(arx_classifier) +export(arx_fcast_epi_workflow) export(arx_forecaster) export(bake) export(create_layer) export(default_epi_recipe_blueprint) export(detect_layer) -export(df_mat_mul) export(dist_quantiles) export(epi_keys) export(epi_recipe) diff --git a/R/arx_classifier.R b/R/arx_classifier.R index 78a80534b..17e8a9c9d 100644 --- a/R/arx_classifier.R +++ b/R/arx_classifier.R @@ -11,12 +11,13 @@ #' trainers like [parsnip::naive_Bayes()] or [parsnip::rand_forest()] can #' also be used. #' @param args_list A list of customization arguments to determine -#' the type of forecasting model. See [arx_args_list()]. +#' the type of forecasting model. See [arx_class_args_list()]. #' #' @return A list with (1) `predictions` an `epi_df` of predicted classes #' and (2) `epi_workflow`, a list that encapsulates the entire estimation #' workflow #' @export +#' @seealso [arx_class_epi_workflow()], [arx_class_args_list()] #' #' @examples #' jhu <- case_death_rate_subset %>% @@ -34,18 +35,87 @@ #' horizon = 14, method = "linear_reg" #' ) #' ) -arx_classifier <- function(epi_data, - outcome, - predictors, - trainer = parsnip::logistic_reg(), - args_list = arx_class_args_list()) { +arx_classifier <- function( + epi_data, + outcome, + predictors, + trainer = parsnip::logistic_reg(), + args_list = arx_class_args_list()) { - # --- validation - validate_forecaster_inputs(epi_data, outcome, predictors) - if (!inherits(args_list, "arx_clist")) - cli_stop("args_list was not created using `arx_class_args_list().") if (!is_classification(trainer)) - cli_stop("{trainer} must be a `parsnip` method of mode 'classification'.") + cli::cli_abort("`trainer` must be a {.pkg parsnip} model of mode 'classification'.") + + wf <- arx_class_epi_workflow( + epi_data, outcome, predictors, trainer, args_list + ) + + latest <- get_test_data( + workflows::extract_preprocessor(wf), epi_data, TRUE + ) + + wf <- generics::fit(wf, epi_data) + preds <- predict(wf, new_data = latest) %>% + tibble::as_tibble() %>% + dplyr::select(-time_value) + + structure(list( + predictions = preds, + epi_workflow = wf, + metadata = list( + training = attr(epi_data, "metadata"), + forecast_created = Sys.time() + )), + class = c("arx_class", "canned_epipred") + ) +} + + +#' Create a template `arx_classifier` workflow +#' +#' This function creates an unfit workflow for use with [arx_classifier()]. +#' It is useful if you want to make small modifications to that classifier +#' before fitting and predicting. Supplying a trainer to the function +#' may alter the returned `epi_workflow` object but can be omitted. +#' +#' @inheritParams arx_classifier +#' @param trainer A `{parsnip}` model describing the type of estimation. +#' For now, we enforce `mode = "classification"`. Typical values are +#' [parsnip::logistic_reg()] or [parsnip::multinom_reg()]. More complicated +#' trainers like [parsnip::naive_Bayes()] or [parsnip::rand_forest()] can +#' also be used. May be `NULL` (the default). +#' +#' @return An unfit `epi_workflow`. +#' @export +#' @seealso [arx_classifier()] +#' @examples +#' +#' jhu <- case_death_rate_subset %>% +#' dplyr::filter(time_value >= as.Date("2021-11-01")) +#' +#' arx_class_epi_workflow(jhu, "death_rate", c("case_rate", "death_rate")) +#' +#' arx_class_epi_workflow( +#' jhu, +#' "death_rate", +#' c("case_rate", "death_rate"), +#' trainer = parsnip::multinom_reg(), +#' args_list = arx_class_args_list( +#' breaks = c(-.05, .1), ahead = 14, +#' horizon = 14, method = "linear_reg" +#' ) +#' ) +arx_class_epi_workflow <- function( + epi_data, + outcome, + predictors, + trainer = NULL, + args_list = arx_class_args_list()) { + + validate_forecaster_inputs(epi_data, outcome, predictors) + if (!inherits(args_list, c("arx_class", "alist"))) + rlang::abort("args_list was not created using `arx_class_args_list().") + if (!(is.null(trainer) || is_classification(trainer))) + rlang::abort("`trainer` must be a `{parsnip}` model of mode 'classification'.") lags <- arx_lags_validator(predictors, args_list$lags) # --- preprocessor @@ -108,18 +178,9 @@ arx_classifier <- function(epi_data, f <- layer_add_forecast_date(f, forecast_date = forecast_date) %>% layer_add_target_date(target_date = target_date) - - # --- create test data, fit, and return - latest <- get_test_data(r, epi_data, TRUE) - wf <- epi_workflow(r, trainer, f) %>% generics::fit(epi_data) - list( - predictions = predict(wf, new_data = latest), - epi_workflow = wf - ) + epi_workflow(r, trainer, f) } - - #' ARX classifier argument constructor #' #' Constructs a list of arguments for [arx_classifier()]. @@ -190,8 +251,9 @@ arx_class_args_list <- function( arg_is_pos(n_training) if (is.finite(n_training)) arg_is_pos_int(n_training) if (!is.list(additional_gr_args)) { - rlang::abort( - c("`additional_gr_args` must be a list.", + cli::cli_abort( + c("`additional_gr_args` must be a {.cls list}.", + "!" = "This is a {.cls {class(additional_gr_args)}}.", i = "See `?epiprocess::growth_rate` for available arguments.") ) } @@ -216,11 +278,13 @@ arx_class_args_list <- function( log_scale, additional_gr_args ), - class = "arx_clist" + class = c("arx_class", "alist") ) } #' @export -print.arx_clist <- function(x, ...) { - utils::str(x) +print.arx_class <- function(x, ...) { + name <- "ARX Classifier" + NextMethod(name = name, ...) } + diff --git a/R/arx_forecaster.R b/R/arx_forecaster.R index 34612202a..d883f3e2a 100644 --- a/R/arx_forecaster.R +++ b/R/arx_forecaster.R @@ -19,6 +19,7 @@ #' and (2) `epi_workflow`, a list that encapsulates the entire estimation #' workflow #' @export +#' @seealso [arx_fcast_epi_workflow()], [arx_args_list()] #' #' @examples #' jhu <- case_death_rate_subset %>% @@ -36,12 +37,72 @@ arx_forecaster <- function(epi_data, trainer = parsnip::linear_reg(), args_list = arx_args_list()) { + if (!is_regression(trainer)) + cli::cli_abort("`trainer` must be a {.pkg parsnip} model of mode 'regression'.") + + wf <- arx_fcast_epi_workflow( + epi_data, outcome, predictors, trainer, args_list + ) + + latest <- get_test_data( + workflows::extract_preprocessor(wf), epi_data, TRUE + ) + + wf <- generics::fit(wf, epi_data) + preds <- predict(wf, new_data = latest) %>% + tibble::as_tibble() %>% + dplyr::select(-time_value) + + structure(list( + predictions = preds, + epi_workflow = wf, + metadata = list( + training = attr(epi_data, "metadata"), + forecast_created = Sys.time() + )), + class = c("arx_fcast", "canned_epipred") + ) +} + +#' Create a template `arx_forecaster` workflow +#' +#' This function creates an unfit workflow for use with [arx_forecaster()]. +#' It is useful if you want to make small modifications to that forecaster +#' before fitting and predicting. Supplying a trainer to the function +#' may alter the returned `epi_workflow` object (e.g., if you intend to +#' use [quantile_reg()]) but can be omitted. +#' +#' @inheritParams arx_forecaster +#' @param trainer A `{parsnip}` model describing the type of estimation. +#' For now, we enforce `mode = "regression"`. May be `NULL` (the default). +#' +#' @return An unfitted `epi_workflow`. +#' @export +#' @seealso [arx_forecaster()] +#' +#' @examples +#' jhu <- case_death_rate_subset %>% +#' dplyr::filter(time_value >= as.Date("2021-12-01")) +#' +#' arx_fcast_epi_workflow(jhu, "death_rate", +#' c("case_rate", "death_rate")) +#' +#' arx_fcast_epi_workflow(jhu, "death_rate", +#' c("case_rate", "death_rate"), trainer = quantile_reg(), +#' args_list = arx_args_list(levels = 1:9 / 10)) +arx_fcast_epi_workflow <- function( + epi_data, + outcome, + predictors, + trainer = NULL, + args_list = arx_args_list()) { + # --- validation validate_forecaster_inputs(epi_data, outcome, predictors) - if (!inherits(args_list, "arx_flist")) - cli_stop("args_list was not created using `arx_args_list().") - if (!is_regression(trainer)) - cli_stop("{trainer} must be a `parsnip` method of mode 'regression'.") + if (!inherits(args_list, c("arx_fcast", "alist"))) + cli::cli_abort("args_list was not created using `arx_args_list().") + if (!(is.null(trainer) || is_regression(trainer))) + cli::cli_abort("{trainer} must be a `{parsnip}` model of mode 'regression'.") lags <- arx_lags_validator(predictors, args_list$lags) # --- preprocessor @@ -74,28 +135,10 @@ arx_forecaster <- function(epi_data, layer_add_target_date(target_date = target_date) if (args_list$nonneg) f <- layer_threshold(f, dplyr::starts_with(".pred")) - # --- create test data, fit, and return - latest <- get_test_data(r, epi_data, TRUE) - wf <- epi_workflow(r, trainer, f) %>% generics::fit(epi_data) - list( - predictions = predict(wf, new_data = latest), - epi_workflow = wf - ) + epi_workflow(r, trainer, f) } -arx_lags_validator <- function(predictors, lags) { - p <- length(predictors) - if (!is.list(lags)) lags <- list(lags) - if (length(lags) == 1) lags <- rep(lags, p) - else if (length(lags) < p) { - cli_stop( - "You have requested {p} predictors but lags cannot be recycled to match." - ) - } - lags -} - #' ARX forecaster argument constructor #' #' Constructs a list of arguments for [arx_forecaster()]. @@ -130,15 +173,16 @@ arx_lags_validator <- function(predictors, lags) { #' arx_args_list() #' arx_args_list(symmetrize = FALSE) #' arx_args_list(levels = c(.1, .3, .7, .9), n_training = 120) -arx_args_list <- function(lags = c(0L, 7L, 14L), - ahead = 7L, - n_training = Inf, - forecast_date = NULL, - target_date = NULL, - levels = c(0.05, 0.95), - symmetrize = TRUE, - nonneg = TRUE, - quantile_by_key = character(0L)) { +arx_args_list <- function( + lags = c(0L, 7L, 14L), + ahead = 7L, + n_training = Inf, + forecast_date = NULL, + target_date = NULL, + levels = c(0.05, 0.95), + symmetrize = TRUE, + nonneg = TRUE, + quantile_by_key = character(0L)) { # error checking if lags is a list .lags <- lags @@ -155,20 +199,24 @@ arx_args_list <- function(lags = c(0L, 7L, 14L), if (is.finite(n_training)) arg_is_pos_int(n_training) max_lags <- max(lags) - structure(enlist(lags = .lags, - ahead, - n_training, - levels, - forecast_date, - target_date, - symmetrize, - nonneg, - max_lags, - quantile_by_key), - class = "arx_flist") + structure( + enlist(lags = .lags, + ahead, + n_training, + levels, + forecast_date, + target_date, + symmetrize, + nonneg, + max_lags, + quantile_by_key), + class = c("arx_fcast", "alist") + ) } + #' @export -print.arx_flist <- function(x, ...) { - utils::str(x) +print.arx_fcast <- function(x, ...) { + name <- "ARX Forecaster" + NextMethod(name = name, ...) } diff --git a/R/canned-epipred.R b/R/canned-epipred.R new file mode 100644 index 000000000..d2b4af22f --- /dev/null +++ b/R/canned-epipred.R @@ -0,0 +1,74 @@ +validate_forecaster_inputs <- function(epi_data, outcome, predictors) { + if (!epiprocess::is_epi_df(epi_data)) { + cli::cli_abort(c( + "`epi_data` must be an {.cls epi_df}.", + "!" = "This one is a {.cls {class(epi_data)}}." + )) + } + arg_is_chr(predictors) + arg_is_chr_scalar(outcome) + if (!outcome %in% names(epi_data)) + cli::cli_abort("{outcome} was not found in the training data.") + check <- hardhat::check_column_names(epi_data, predictors) + if (!check$ok) { + cli::cli_abort(c( + "At least one predictor was not found in the training data.", + "!" = "The following required columns are missing: {check$missing_names}." + )) + } + invisible(TRUE) +} + + +arx_lags_validator <- function(predictors, lags) { + p <- length(predictors) + if (!is.list(lags)) lags <- list(lags) + l <- length(lags) + if (l == 1) lags <- rep(lags, p) + else if (length(lags) != p) { + cli::cli_abort(c( + "You have requested {p} predictor(s) but {l} different lags.", + i = "Lags must be a vector or a list with length == number of predictors." + )) + } + lags +} + + +#' @export +print.alist <- function(x, ...) { + utils::str(x) +} + +#' @export +print.canned_epipred <- function(x, name, ...) { + cat("\n") + cli::cli_rule("A basic forecaster of type {.pkg {name}}") + + cat("\n") + cli::cli_text( + "This forecaster was fit on {.val {format(x$metadata$forecast_created)}}." + ) + cat("\n") + cli::cli_text("Training data was an {.cls epi_df} with ") + cli::cli_ul(c( + "Geography: {.val {x$metadata$training$geo_type}},", + "Time type: {.val {x$metadata$training$time_type}},", + "Using data up-to-date as of: {.val {format(x$metadata$training$as_of)}}." + )) + + cat("\n") + cli::cli_rule("Predictions") + n_geos <- dplyr::n_distinct(x$predictions$geo_value) + fds <- unique(x$predictions$forecast_date) + tds <- unique(x$predictions$target_date) + + cat("\n") + cli::cli_text("A total of {nrow(x$predictions)} predictions are available for") + cli::cli_ul(c( + "{n_geos} unique geographic regions,", + "At forecast dates: {.val {fds}},", + "For target dates: {.val {tds}}." + )) + cat("\n") +} diff --git a/R/flatline_forecaster.R b/R/flatline_forecaster.R index 0eb718b52..8843f10fe 100644 --- a/R/flatline_forecaster.R +++ b/R/flatline_forecaster.R @@ -33,7 +33,7 @@ flatline_forecaster <- function( args_list = flatline_args_list()) { validate_forecaster_inputs(epi_data, outcome, "time_value") - if (!inherits(args_list, "flatline_alist")) { + if (!inherits(args_list, c("flatline", "alist"))) { cli_stop("args_list was not created using `flatline_args_list().") } keys <- epi_keys(epi_data) @@ -64,11 +64,21 @@ flatline_forecaster <- function( eng <- parsnip::linear_reg() %>% parsnip::set_engine("flatline") - wf <- epi_workflow(r, eng, f) %>% fit(epi_data) - - list( - predictions = suppressWarnings(predict(wf, new_data = latest)), - epi_workflow = wf + wf <- epi_workflow(r, eng, f) + + wf <- generics::fit(wf, epi_data) + preds <- suppressWarnings(predict(wf, new_data = latest)) %>% + tibble::as_tibble() %>% + dplyr::select(-time_value) + + structure(list( + predictions = preds, + epi_workflow = wf, + metadata = list( + training = attr(epi_data, "metadata"), + forecast_created = Sys.time() + )), + class = c("flatline", "canned_epipred") ) } @@ -107,32 +117,21 @@ flatline_args_list <- function( arg_is_pos(n_training) if (is.finite(n_training)) arg_is_pos_int(n_training) - structure(enlist(ahead, - n_training, - forecast_date, - target_date, - levels, - symmetrize, - nonneg, - quantile_by_key), - class = "flatline_alist") -} - -validate_forecaster_inputs <- function(epi_data, outcome, predictors) { - if (!epiprocess::is_epi_df(epi_data)) - cli_stop("epi_data must be an epi_df.") - arg_is_chr(predictors) - arg_is_chr_scalar(outcome) - if (!outcome %in% names(epi_data)) - cli_stop("{outcome} was not found in the training data.") - if (!all(predictors %in% names(epi_data))) - cli_stop("At least one predictor was not found in the training data.") - invisible(TRUE) + structure( + enlist(ahead, + n_training, + forecast_date, + target_date, + levels, + symmetrize, + nonneg, + quantile_by_key), + class = c("flatline", "alist") + ) } #' @export -print.flatline_alist <- function(x, ...) { - utils::str(x) +print.flatline <- function(x, ...) { + name <- "flatline" + NextMethod(name = name, ...) } - - diff --git a/R/utils-misc.R b/R/utils-misc.R index 0fca30064..93b2baa9f 100644 --- a/R/utils-misc.R +++ b/R/utils-misc.R @@ -60,9 +60,7 @@ grab_forged_keys <- function(forged, mold, new_data) { } get_parsnip_mode <- function(trainer) { - if (inherits(trainer, "model_spec")) { - return(trainer$mode) - } + if (inherits(trainer, "model_spec")) return(trainer$mode) cc <- class(trainer) cli::cli_abort( c("`trainer` must be a `parsnip` model.", diff --git a/man/arx_class_epi_workflow.Rd b/man/arx_class_epi_workflow.Rd new file mode 100644 index 000000000..aaaf20cc9 --- /dev/null +++ b/man/arx_class_epi_workflow.Rd @@ -0,0 +1,62 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/arx_classifier.R +\name{arx_class_epi_workflow} +\alias{arx_class_epi_workflow} +\title{Create a template \code{arx_classifier} workflow} +\usage{ +arx_class_epi_workflow( + epi_data, + outcome, + predictors, + trainer = NULL, + args_list = arx_class_args_list() +) +} +\arguments{ +\item{epi_data}{An \code{epi_df} object} + +\item{outcome}{A character (scalar) specifying the outcome (in the +\code{epi_df}).} + +\item{predictors}{A character vector giving column(s) of predictor +variables.} + +\item{trainer}{A \code{{parsnip}} model describing the type of estimation. +For now, we enforce \code{mode = "classification"}. Typical values are +\code{\link[parsnip:logistic_reg]{parsnip::logistic_reg()}} or \code{\link[parsnip:multinom_reg]{parsnip::multinom_reg()}}. More complicated +trainers like \code{\link[parsnip:naive_Bayes]{parsnip::naive_Bayes()}} or \code{\link[parsnip:rand_forest]{parsnip::rand_forest()}} can +also be used. May be \code{NULL} (the default).} + +\item{args_list}{A list of customization arguments to determine +the type of forecasting model. See \code{\link[=arx_class_args_list]{arx_class_args_list()}}.} +} +\value{ +An unfit \code{epi_workflow}. +} +\description{ +This function creates an unfit workflow for use with \code{\link[=arx_classifier]{arx_classifier()}}. +It is useful if you want to make small modifications to that classifier +before fitting and predicting. Supplying a trainer to the function +may alter the returned \code{epi_workflow} object but can be omitted. +} +\examples{ + +jhu <- case_death_rate_subset \%>\% + dplyr::filter(time_value >= as.Date("2021-11-01")) + +arx_class_epi_workflow(jhu, "death_rate", c("case_rate", "death_rate")) + +arx_class_epi_workflow( + jhu, + "death_rate", + c("case_rate", "death_rate"), + trainer = parsnip::multinom_reg(), + args_list = arx_class_args_list( + breaks = c(-.05, .1), ahead = 14, + horizon = 14, method = "linear_reg" + ) +) +} +\seealso{ +\code{\link[=arx_classifier]{arx_classifier()}} +} diff --git a/man/arx_classifier.Rd b/man/arx_classifier.Rd index 942a64787..b6227a5a6 100644 --- a/man/arx_classifier.Rd +++ b/man/arx_classifier.Rd @@ -28,7 +28,7 @@ trainers like \code{\link[parsnip:naive_Bayes]{parsnip::naive_Bayes()}} or \code also be used.} \item{args_list}{A list of customization arguments to determine -the type of forecasting model. See \code{\link[=arx_args_list]{arx_args_list()}}.} +the type of forecasting model. See \code{\link[=arx_class_args_list]{arx_class_args_list()}}.} } \value{ A list with (1) \code{predictions} an \code{epi_df} of predicted classes @@ -57,3 +57,6 @@ out <- arx_classifier( ) ) } +\seealso{ +\code{\link[=arx_class_epi_workflow]{arx_class_epi_workflow()}}, \code{\link[=arx_class_args_list]{arx_class_args_list()}} +} diff --git a/man/arx_fcast_epi_workflow.Rd b/man/arx_fcast_epi_workflow.Rd new file mode 100644 index 000000000..fdd309959 --- /dev/null +++ b/man/arx_fcast_epi_workflow.Rd @@ -0,0 +1,53 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/arx_forecaster.R +\name{arx_fcast_epi_workflow} +\alias{arx_fcast_epi_workflow} +\title{Create a template \code{arx_forecaster} workflow} +\usage{ +arx_fcast_epi_workflow( + epi_data, + outcome, + predictors, + trainer = NULL, + args_list = arx_args_list() +) +} +\arguments{ +\item{epi_data}{An \code{epi_df} object} + +\item{outcome}{A character (scalar) specifying the outcome (in the +\code{epi_df}).} + +\item{predictors}{A character vector giving column(s) of predictor +variables.} + +\item{trainer}{A \code{{parsnip}} model describing the type of estimation. +For now, we enforce \code{mode = "regression"}. May be \code{NULL} (the default).} + +\item{args_list}{A list of customization arguments to determine +the type of forecasting model. See \code{\link[=arx_args_list]{arx_args_list()}}.} +} +\value{ +An unfitted \code{epi_workflow}. +} +\description{ +This function creates an unfit workflow for use with \code{\link[=arx_forecaster]{arx_forecaster()}}. +It is useful if you want to make small modifications to that forecaster +before fitting and predicting. Supplying a trainer to the function +may alter the returned \code{epi_workflow} object (e.g., if you intend to +use \code{\link[=quantile_reg]{quantile_reg()}}) but can be omitted. +} +\examples{ +jhu <- case_death_rate_subset \%>\% + dplyr::filter(time_value >= as.Date("2021-12-01")) + +arx_fcast_epi_workflow(jhu, "death_rate", + c("case_rate", "death_rate")) + +arx_fcast_epi_workflow(jhu, "death_rate", + c("case_rate", "death_rate"), trainer = quantile_reg(), + args_list = arx_args_list(levels = 1:9 / 10)) +} +\seealso{ +\code{\link[=arx_forecaster]{arx_forecaster()}} +} diff --git a/man/arx_forecaster.Rd b/man/arx_forecaster.Rd index 46367d844..d4866aa0e 100644 --- a/man/arx_forecaster.Rd +++ b/man/arx_forecaster.Rd @@ -48,3 +48,6 @@ out <- arx_forecaster(jhu, "death_rate", c("case_rate", "death_rate"), trainer = quantile_reg(), args_list = arx_args_list(levels = 1:9 / 10)) } +\seealso{ +\code{\link[=arx_fcast_epi_workflow]{arx_fcast_epi_workflow()}}, \code{\link[=arx_args_list]{arx_args_list()}} +} diff --git a/man/df_mat_mul.Rd b/man/df_mat_mul.Rd deleted file mode 100644 index 57596dd2d..000000000 --- a/man/df_mat_mul.Rd +++ /dev/null @@ -1,35 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/df_mat_mul.R -\name{df_mat_mul} -\alias{df_mat_mul} -\title{Multiply columns of a \code{data.frame} by a matrix} -\usage{ -df_mat_mul(dat, mat, out_names = "out", ...) -} -\arguments{ -\item{dat}{A data.frame} - -\item{mat}{A matrix} - -\item{out_names}{Character vector. Creates the names of the resulting -columns after multiplication. If a scalar, this is treated as a -prefix and the remaining columns will be numbered sequentially.} - -\item{...}{<\code{\link[dplyr:dplyr_tidy_select]{tidy-select}}> One or more unquoted -expressions separated by commas. Variable names can be used as if they -were positions in the data frame, so expressions like \code{x:y} can -be used to select a range of variables.} -} -\value{ -A data.frame with the new columns at the right. Original -columns are removed. -} -\description{ -Multiply columns of a \code{data.frame} by a matrix -} -\examples{ -df <- data.frame(matrix(1:200, ncol = 10)) -mat <- matrix(1:10, ncol = 2) -df_mat_mul(df, mat, "z", dplyr::num_range("X", 2:6)) -} -\keyword{internal} diff --git a/man/layer_predict.Rd b/man/layer_predict.Rd index e0986bdf5..1326dfe75 100644 --- a/man/layer_predict.Rd +++ b/man/layer_predict.Rd @@ -42,7 +42,7 @@ the standard error of fit or prediction (on the scale of the linear predictors). Default value is \code{FALSE}. \item \code{quantile}: for \code{type} equal to \code{quantile}, the quantiles of the distribution. Default is \code{(1:9)/10}. -\item \code{time}: for \code{type} equal to \code{"survival"} or \code{"hazard"}, the +\item \code{eval_time}: for \code{type} equal to \code{"survival"} or \code{"hazard"}, the time points at which the survival probability or hazard is estimated. }} diff --git a/man/predict-epi_workflow.Rd b/man/predict-epi_workflow.Rd index 5058e4bb4..d92fd8ca9 100644 --- a/man/predict-epi_workflow.Rd +++ b/man/predict-epi_workflow.Rd @@ -31,7 +31,7 @@ the standard error of fit or prediction (on the scale of the linear predictors). Default value is \code{FALSE}. \item \code{quantile}: for \code{type} equal to \code{quantile}, the quantiles of the distribution. Default is \code{(1:9)/10}. -\item \code{time}: for \code{type} equal to \code{"survival"} or \code{"hazard"}, the +\item \code{eval_time}: for \code{type} equal to \code{"survival"} or \code{"hazard"}, the time points at which the survival probability or hazard is estimated. }} } diff --git a/R/df_mat_mul.R b/musings/df_mat_mul.R similarity index 100% rename from R/df_mat_mul.R rename to musings/df_mat_mul.R diff --git a/tests/testthat/test-df_mat_mul.R b/musings/test-df_mat_mul.R similarity index 100% rename from tests/testthat/test-df_mat_mul.R rename to musings/test-df_mat_mul.R diff --git a/tests/testthat/test-arx_args_list.R b/tests/testthat/test-arx_args_list.R index 834dd8996..25e3194de 100644 --- a/tests/testthat/test-arx_args_list.R +++ b/tests/testthat/test-arx_args_list.R @@ -1,5 +1,5 @@ test_that("arx_args checks inputs", { - expect_s3_class(arx_args_list(), "arx_flist") + expect_s3_class(arx_args_list(), c("arx_fcast", "alist")) expect_error(arx_args_list(ahead = c(0, 4))) expect_error(arx_args_list(n_training = c(28, 65))) diff --git a/tests/testthat/test-arx_cargs_list.R b/tests/testthat/test-arx_cargs_list.R index 699bba94b..40035890d 100644 --- a/tests/testthat/test-arx_cargs_list.R +++ b/tests/testthat/test-arx_cargs_list.R @@ -1,5 +1,5 @@ test_that("arx_class_args checks inputs", { - expect_s3_class(arx_class_args_list(), "arx_clist") + expect_s3_class(arx_class_args_list(), c("arx_class", "alist")) expect_error(arx_class_args_list(ahead = c(0, 4))) expect_error(arx_class_args_list(n_training = c(28, 65)))