From 43bbddbf9e2290e26adf2f1595ddd930bc8faa08 Mon Sep 17 00:00:00 2001 From: bernie gray Date: Sat, 9 Jun 2018 16:07:41 -0400 Subject: [PATCH] Throw informative error for glance.rqs. Closes #330. (#338) --- R/rq_tidiers.R | 11 ++++++++++- tests/testthat/test-rq.R | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/R/rq_tidiers.R b/R/rq_tidiers.R index 72795f259..0f2e07eac 100644 --- a/R/rq_tidiers.R +++ b/R/rq_tidiers.R @@ -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} @@ -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 #' diff --git a/tests/testthat/test-rq.R b/tests/testthat/test-rq.R index a52b13d66..2327f6dc4 100644 --- a/tests/testthat/test-rq.R +++ b/tests/testthat/test-rq.R @@ -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)