Skip to content

Commit

Permalink
Throw informative error for glance.rqs. Closes #330. (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
bfgray3 authored and alexpghayes committed Jun 9, 2018
1 parent 188c095 commit 43bbddb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion R/rq_tidiers.R
Expand Up @@ -78,6 +78,10 @@ tidy.nlrq <- function(x, conf.int = FALSE, conf.level = 0.95, ...) {

#' @rdname rq_tidiers
#'
#' @details Only models with a single \code{tau} value may be passed.
#' For multiple values, please use a \code{purrr::map} workflow instead,
#' e.g. \code{taus %>% map(function(tau_val) rq(y ~ x, tau = tau_val)) %>% map_dfr(glance)}.
#'
#' @return \code{glance.rq} returns one row for each quantile (tau)
#' with the columns:
#' \item{tau}{quantile estimated}
Expand All @@ -99,7 +103,12 @@ glance.rq <- function(x, ...) {
}

#' @export
glance.rqs <- glance.rq
glance.rqs <- function(x, ...) {
stop("`glance` cannot handle objects of class 'rqs',",
" i.e. models with more than one tau value. Please",
" use a `purr::map`-based workflow with 'rq' models instead.",
call. = FALSE)
}

#' @rdname rq_tidiers
#'
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-rq.R
Expand Up @@ -29,6 +29,12 @@ test_that("rqs tidiers work", {
td <- tidy(fit)
check_tidy(td, exp.row = 114, exp.col = 5)

rqs_glance_error <- paste("`glance` cannot handle objects of class 'rqs',",
"i.e. models with more than one tau value. Please",
"use a `purr::map`-based workflow with 'rq' models instead.")

expect_error(glance(fit), regexp = rqs_glance_error)

au <- augment(fit)
check_tidy(au, exp.row = 2109, exp.col = 9)

Expand Down

0 comments on commit 43bbddb

Please sign in to comment.