R/accessors.R

Defines functions mable_vars.mdl_df mable_vars distribution_var.fbl_ts distribution_var response_vars.dcmp_ts response_vars.mdl_ts response_vars.mdl_df response_vars.fbl_ts response_vars

Documented in distribution_var mable_vars response_vars

#' Return response variables
#' 
#' `response_vars()` returns a character vector of the response variables in the
#' object.
#' 
#' @param x A dataset containing a response variable (such as a mable, fable, or dable).
#' @export
response_vars <- function(x){
  UseMethod("response_vars")
}

#' @export
response_vars.fbl_ts <- function(x){
  x%@%"response"
}
#' @export
response_vars.mdl_df <- function(x){
  x%@%"response"
}
#' @export
response_vars.mdl_ts <- function(x){
  vapply(x$response, rlang::as_label, FUN.VALUE = character(1L))
}
#' @export
response_vars.dcmp_ts <- function(x){
  x%@%"response"
}

#' Return distribution variable
#' 
#' `distribution_var()` returns a character vector of the distribution variable 
#' in the data.
#' 
#' @param x A dataset containing a distribution variable (such as a fable).
#' @export
distribution_var <- function(x){
  UseMethod("distribution_var")
}
#' @export
distribution_var.fbl_ts <- function(x){
  x%@%"dist"
}

#' Return model column variables
#' 
#' `mable_vars()` returns a character vector of the model variables in the
#' object.
#' 
#' @param x A dataset containing models (such as a mable).
#' @export
mable_vars <- function(x){
  UseMethod("mable_vars")
}
#' @export
mable_vars.mdl_df <- function(x){
  x%@%"model"
}

Try the fabletools package in your browser

Any scripts or data that you put into this service are public.

fabletools documentation built on Oct. 12, 2023, 1:07 a.m.