From 508e1bc315789a7c3ae37226830da3647647ee25 Mon Sep 17 00:00:00 2001 From: Bernie Gray Date: Mon, 6 May 2019 23:40:31 -0400 Subject: [PATCH 01/12] default formula argument to NULL in geom_smooth(); closes #3205 --- NEWS.md | 2 ++ R/geom-smooth.r | 2 +- R/stat-smooth.r | 11 +++++++---- man/geom_smooth.Rd | 8 +++++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4699714a4a..3865e33b17 100644 --- a/NEWS.md +++ b/NEWS.md @@ -66,6 +66,8 @@ core developer team. ## Minor improvements and bug fixes +* The `formula` argument to `geom_smooth()` now defaults to `NULL` and is filled in with the approprate formula in the function body (@bfgray3, #3205). + * `cut_width()` now accepts `...` to pass further arguments to `base::cut.default()` like `cut_number()` and `cut_interval()` already did (@cderv, #3055) diff --git a/R/geom-smooth.r b/R/geom-smooth.r index 6c10e98ba5..ceefaa2eea 100644 --- a/R/geom-smooth.r +++ b/R/geom-smooth.r @@ -79,7 +79,7 @@ geom_smooth <- function(mapping = NULL, data = NULL, stat = "smooth", position = "identity", ..., method = "auto", - formula = y ~ x, + formula = NULL, se = TRUE, na.rm = FALSE, show.legend = NA, diff --git a/R/stat-smooth.r b/R/stat-smooth.r index fecc2842e1..4434cd02ec 100644 --- a/R/stat-smooth.r +++ b/R/stat-smooth.r @@ -13,7 +13,9 @@ #' model that `method = "auto"` would use, then set #' `method = "gam", formula = y ~ s(x, bs = "cs")`. #' @param formula Formula to use in smoothing function, eg. `y ~ x`, -#' `y ~ poly(x, 2)`, `y ~ log(x)` +#' `y ~ poly(x, 2)`, `y ~ log(x)`. `NULL` by default, in which case +#' `method = "auto"` implies `formula = y ~ x` when there are fewer than 1,000 +#' observations and `formula = y ~ s(x, bs = "cs")` otherwise. #' @param se Display confidence interval around smooth? (`TRUE` by default, see #' `level` to control.) #' @param fullrange Should the fit span the full range of the plot, or just @@ -38,7 +40,7 @@ stat_smooth <- function(mapping = NULL, data = NULL, geom = "smooth", position = "identity", ..., method = "auto", - formula = y ~ x, + formula = NULL, se = TRUE, n = 80, span = 0.75, @@ -86,9 +88,10 @@ StatSmooth <- ggproto("StatSmooth", Stat, if (max_group < 1000) { params$method <- "loess" + params$formula <- params$formula %||% (y ~ x) } else { params$method <- "gam" - params$formula <- y ~ s(x, bs = "cs") + params$formula <- params$formula %||% (y ~ s(x, bs = "cs")) } message("`geom_smooth()` using method = '", params$method, "' and formula '", deparse(params$formula), "'") @@ -100,7 +103,7 @@ StatSmooth <- ggproto("StatSmooth", Stat, params }, - compute_group = function(data, scales, method = "auto", formula = y~x, + compute_group = function(data, scales, method = "auto", formula = NULL, se = TRUE, n = 80, span = 0.75, fullrange = FALSE, xseq = NULL, level = 0.95, method.args = list(), na.rm = FALSE) { diff --git a/man/geom_smooth.Rd b/man/geom_smooth.Rd index b1e0f69682..3e3e54c45d 100644 --- a/man/geom_smooth.Rd +++ b/man/geom_smooth.Rd @@ -6,11 +6,11 @@ \title{Smoothed conditional means} \usage{ geom_smooth(mapping = NULL, data = NULL, stat = "smooth", - position = "identity", ..., method = "auto", formula = y ~ x, + position = "identity", ..., method = "auto", formula = NULL, se = TRUE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) stat_smooth(mapping = NULL, data = NULL, geom = "smooth", - position = "identity", ..., method = "auto", formula = y ~ x, + position = "identity", ..., method = "auto", formula = NULL, se = TRUE, n = 80, span = 0.75, fullrange = FALSE, level = 0.95, method.args = list(), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) @@ -60,7 +60,9 @@ model that \code{method = "auto"} would use, then set \code{method = "gam", formula = y ~ s(x, bs = "cs")}.} \item{formula}{Formula to use in smoothing function, eg. \code{y ~ x}, -\code{y ~ poly(x, 2)}, \code{y ~ log(x)}} +\code{y ~ poly(x, 2)}, \code{y ~ log(x)}. \code{NULL} by default, in which case +\code{method = "auto"} implies \code{formula = y ~ x} when there are fewer than 1,000 +observations and \code{formula = y ~ s(x, bs = "cs")} otherwise.} \item{se}{Display confidence interval around smooth? (\code{TRUE} by default, see \code{level} to control.)} From 4bb34e354c46aebc7f218c37ee5cc9bc75afbb9d Mon Sep 17 00:00:00 2001 From: Bernie Gray Date: Mon, 13 May 2019 20:39:24 -0400 Subject: [PATCH 02/12] remove news bullet for now since deadline for release has passed --- NEWS.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3865e33b17..4699714a4a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -66,8 +66,6 @@ core developer team. ## Minor improvements and bug fixes -* The `formula` argument to `geom_smooth()` now defaults to `NULL` and is filled in with the approprate formula in the function body (@bfgray3, #3205). - * `cut_width()` now accepts `...` to pass further arguments to `base::cut.default()` like `cut_number()` and `cut_interval()` already did (@cderv, #3055) From 04b3327106d8e7c2e7de544a6136ed32da2bfcb7 Mon Sep 17 00:00:00 2001 From: Bernie Gray Date: Mon, 13 May 2019 20:43:51 -0400 Subject: [PATCH 03/12] handle NULL formulas more carefully in geom_smooth() --- R/stat-smooth.r | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/stat-smooth.r b/R/stat-smooth.r index 4434cd02ec..5c79e3b1fd 100644 --- a/R/stat-smooth.r +++ b/R/stat-smooth.r @@ -98,6 +98,9 @@ StatSmooth <- ggproto("StatSmooth", Stat, } if (identical(params$method, "gam")) { params$method <- mgcv::gam + params$formula <- y ~ s(x, bs = "cs") + } else { + params$formula <- params$formula %||% (y ~ x) } params From bf963db8637294b8896553fcc056af4e61e9ca67 Mon Sep 17 00:00:00 2001 From: Bernie Gray Date: Mon, 13 May 2019 20:51:59 -0400 Subject: [PATCH 04/12] respect input formuals in geom_smooth() --- R/stat-smooth.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/stat-smooth.r b/R/stat-smooth.r index 5c79e3b1fd..0275665519 100644 --- a/R/stat-smooth.r +++ b/R/stat-smooth.r @@ -98,7 +98,7 @@ StatSmooth <- ggproto("StatSmooth", Stat, } if (identical(params$method, "gam")) { params$method <- mgcv::gam - params$formula <- y ~ s(x, bs = "cs") + params$formula <- params$formula %||% y ~ s(x, bs = "cs") } else { params$formula <- params$formula %||% (y ~ x) } From c4ce320b1ecd15049bdf7a2046d13187ee87e1a4 Mon Sep 17 00:00:00 2001 From: Bernie Gray Date: Thu, 30 May 2019 21:52:35 -0400 Subject: [PATCH 05/12] add parens around formula on rhs of %||% --- R/stat-smooth.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/stat-smooth.r b/R/stat-smooth.r index 0275665519..1124548566 100644 --- a/R/stat-smooth.r +++ b/R/stat-smooth.r @@ -98,7 +98,7 @@ StatSmooth <- ggproto("StatSmooth", Stat, } if (identical(params$method, "gam")) { params$method <- mgcv::gam - params$formula <- params$formula %||% y ~ s(x, bs = "cs") + params$formula <- params$formula %||% (y ~ s(x, bs = "cs")) } else { params$formula <- params$formula %||% (y ~ x) } From c9644c36070ddf961b8737a7a521c7603c5b743d Mon Sep 17 00:00:00 2001 From: Bernie Gray Date: Tue, 4 Jun 2019 21:13:49 -0400 Subject: [PATCH 06/12] only set formula once the method is known --- R/stat-smooth.r | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/stat-smooth.r b/R/stat-smooth.r index 1124548566..c5cc964e0b 100644 --- a/R/stat-smooth.r +++ b/R/stat-smooth.r @@ -88,10 +88,8 @@ StatSmooth <- ggproto("StatSmooth", Stat, if (max_group < 1000) { params$method <- "loess" - params$formula <- params$formula %||% (y ~ x) } else { params$method <- "gam" - params$formula <- params$formula %||% (y ~ s(x, bs = "cs")) } message("`geom_smooth()` using method = '", params$method, "' and formula '", deparse(params$formula), "'") From 0c2826b0560108908b56462b61c481e32a446aa9 Mon Sep 17 00:00:00 2001 From: Bernie Gray Date: Thu, 13 Jun 2019 23:14:31 -0400 Subject: [PATCH 07/12] refactor --- R/geom-smooth.r | 4 ++-- R/stat-smooth.r | 48 +++++++++++++++++++++++++++++++--------------- man/geom_smooth.Rd | 18 +++++++++-------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/R/geom-smooth.r b/R/geom-smooth.r index ceefaa2eea..da992e8305 100644 --- a/R/geom-smooth.r +++ b/R/geom-smooth.r @@ -78,7 +78,7 @@ geom_smooth <- function(mapping = NULL, data = NULL, stat = "smooth", position = "identity", ..., - method = "auto", + method = NULL, formula = NULL, se = TRUE, na.rm = FALSE, @@ -91,7 +91,7 @@ geom_smooth <- function(mapping = NULL, data = NULL, ... ) if (identical(stat, "smooth")) { - params$method <- method + params$method <- if (!is.null(method) && identical(method, "auto")) NULL else method params$formula <- formula } diff --git a/R/stat-smooth.r b/R/stat-smooth.r index c5cc964e0b..211acde24a 100644 --- a/R/stat-smooth.r +++ b/R/stat-smooth.r @@ -1,8 +1,10 @@ -#' @param method Smoothing method (function) to use, accepts either a character vector, -#' e.g. `"auto"`, `"lm"`, `"glm"`, `"gam"`, `"loess"` or a function, e.g. -#' `MASS::rlm` or `mgcv::gam`, `base::lm`, or `base::loess`. +#' @param method Smoothing method (function) to use, accepts either +#' `NULL` or a character vector, e.g. `"lm"`, `"glm"`, `"gam"`, `"loess"` +#' or a function, e.g. `MASS::rlm` or `mgcv::gam`, `stats::lm`, or `stats::loess`. +#' `"auto"` is also accepted for backwards compatibility. It is equivalent to +#' `NULL`. #' -#' For `method = "auto"` the smoothing method is chosen based on the +#' For `method = NULL` the smoothing method is chosen based on the #' size of the largest group (across all panels). [loess()] is #' used for less than 1,000 observations; otherwise [mgcv::gam()] is #' used with `formula = y ~ s(x, bs = "cs")`. Somewhat anecdotally, @@ -10,11 +12,11 @@ #' so does not work for larger datasets. #' #' If you have fewer than 1,000 observations but want to use the same `gam()` -#' model that `method = "auto"` would use, then set +#' model that `method = NULL` would use, then set #' `method = "gam", formula = y ~ s(x, bs = "cs")`. #' @param formula Formula to use in smoothing function, eg. `y ~ x`, #' `y ~ poly(x, 2)`, `y ~ log(x)`. `NULL` by default, in which case -#' `method = "auto"` implies `formula = y ~ x` when there are fewer than 1,000 +#' `method = NULL` implies `formula = y ~ x` when there are fewer than 1,000 #' observations and `formula = y ~ s(x, bs = "cs")` otherwise. #' @param se Display confidence interval around smooth? (`TRUE` by default, see #' `level` to control.) @@ -39,7 +41,7 @@ stat_smooth <- function(mapping = NULL, data = NULL, geom = "smooth", position = "identity", ..., - method = "auto", + method = NULL, formula = NULL, se = TRUE, n = 80, @@ -59,7 +61,7 @@ stat_smooth <- function(mapping = NULL, data = NULL, show.legend = show.legend, inherit.aes = inherit.aes, params = list( - method = method, + method = if (!is.null(method) && identical(method, "auto")) NULL else method, formula = formula, se = se, n = n, @@ -80,7 +82,8 @@ stat_smooth <- function(mapping = NULL, data = NULL, StatSmooth <- ggproto("StatSmooth", Stat, setup_params = function(data, params) { - if (identical(params$method, "auto")) { + msg <- NULL + if (is.null(params$method)) { # Use loess for small datasets, gam with a cubic regression basis for # larger. Based on size of the _largest_ group to avoid bad memory # behaviour of loess @@ -91,20 +94,35 @@ StatSmooth <- ggproto("StatSmooth", Stat, } else { params$method <- "gam" } - message("`geom_smooth()` using method = '", params$method, - "' and formula '", deparse(params$formula), "'") + + msg <- paste0("`geom_smooth()` using method = '", params$method, "'") + } + + if (is.null(params$formula)) { + params$formula <- if (identical(params$method, "gam")) { + y ~ s(x, bs = "cs") + } else { + y ~ x + } + msg <- if (is.null(msg)) { + msg <- paste0("`geom_smooth()` using formula = '", deparse(params$formula), "'") + } else { + msg <- paste0(msg, " and formula '", deparse(params$formula), "'") + } } + if (identical(params$method, "gam")) { params$method <- mgcv::gam - params$formula <- params$formula %||% (y ~ s(x, bs = "cs")) - } else { - params$formula <- params$formula %||% (y ~ x) + } + + if (!is.null(msg)) { + message(msg) } params }, - compute_group = function(data, scales, method = "auto", formula = NULL, + compute_group = function(data, scales, method = NULL, formula = NULL, se = TRUE, n = 80, span = 0.75, fullrange = FALSE, xseq = NULL, level = 0.95, method.args = list(), na.rm = FALSE) { diff --git a/man/geom_smooth.Rd b/man/geom_smooth.Rd index 3e3e54c45d..ad06fc5256 100644 --- a/man/geom_smooth.Rd +++ b/man/geom_smooth.Rd @@ -6,11 +6,11 @@ \title{Smoothed conditional means} \usage{ geom_smooth(mapping = NULL, data = NULL, stat = "smooth", - position = "identity", ..., method = "auto", formula = NULL, + position = "identity", ..., method = NULL, formula = NULL, se = TRUE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) stat_smooth(mapping = NULL, data = NULL, geom = "smooth", - position = "identity", ..., method = "auto", formula = NULL, + position = "identity", ..., method = NULL, formula = NULL, se = TRUE, n = 80, span = 0.75, fullrange = FALSE, level = 0.95, method.args = list(), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) @@ -44,11 +44,13 @@ often aesthetics, used to set an aesthetic to a fixed value, like \code{colour = "red"} or \code{size = 3}. They may also be parameters to the paired geom/stat.} -\item{method}{Smoothing method (function) to use, accepts either a character vector, -e.g. \code{"auto"}, \code{"lm"}, \code{"glm"}, \code{"gam"}, \code{"loess"} or a function, e.g. -\code{MASS::rlm} or \code{mgcv::gam}, \code{base::lm}, or \code{base::loess}. +\item{method}{Smoothing method (function) to use, accepts either +\code{NULL} or a character vector, e.g. \code{"lm"}, \code{"glm"}, \code{"gam"}, \code{"loess"} +or a function, e.g. \code{MASS::rlm} or \code{mgcv::gam}, \code{stats::lm}, or \code{stats::loess}. +\code{"auto"} is also accepted for backwards compatibility. It is equivalent to +\code{NULL}. -For \code{method = "auto"} the smoothing method is chosen based on the +For \code{method = NULL} the smoothing method is chosen based on the size of the largest group (across all panels). \code{\link[=loess]{loess()}} is used for less than 1,000 observations; otherwise \code{\link[mgcv:gam]{mgcv::gam()}} is used with \code{formula = y ~ s(x, bs = "cs")}. Somewhat anecdotally, @@ -56,12 +58,12 @@ used with \code{formula = y ~ s(x, bs = "cs")}. Somewhat anecdotally, so does not work for larger datasets. If you have fewer than 1,000 observations but want to use the same \code{gam()} -model that \code{method = "auto"} would use, then set +model that \code{method = NULL} would use, then set \code{method = "gam", formula = y ~ s(x, bs = "cs")}.} \item{formula}{Formula to use in smoothing function, eg. \code{y ~ x}, \code{y ~ poly(x, 2)}, \code{y ~ log(x)}. \code{NULL} by default, in which case -\code{method = "auto"} implies \code{formula = y ~ x} when there are fewer than 1,000 +\code{method = NULL} implies \code{formula = y ~ x} when there are fewer than 1,000 observations and \code{formula = y ~ s(x, bs = "cs")} otherwise.} \item{se}{Display confidence interval around smooth? (\code{TRUE} by default, see From 5910606e566ec4d872033af79a7c59de36c07771 Mon Sep 17 00:00:00 2001 From: Bernie Gray Date: Thu, 13 Jun 2019 23:24:04 -0400 Subject: [PATCH 08/12] tweak formula message for geom_smooth --- R/stat-smooth.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/stat-smooth.r b/R/stat-smooth.r index 211acde24a..669aca42fc 100644 --- a/R/stat-smooth.r +++ b/R/stat-smooth.r @@ -105,7 +105,7 @@ StatSmooth <- ggproto("StatSmooth", Stat, y ~ x } msg <- if (is.null(msg)) { - msg <- paste0("`geom_smooth()` using formula = '", deparse(params$formula), "'") + msg <- paste0("`geom_smooth()` using formula '", deparse(params$formula), "'") } else { msg <- paste0(msg, " and formula '", deparse(params$formula), "'") } From 99e9ad2481c01d583a3cd6b51e05b797489891af Mon Sep 17 00:00:00 2001 From: Bernie Gray Date: Sat, 15 Jun 2019 21:37:25 -0400 Subject: [PATCH 09/12] clean up smoothing message --- R/geom-smooth.r | 2 +- R/stat-smooth.r | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/R/geom-smooth.r b/R/geom-smooth.r index da992e8305..a4e224450f 100644 --- a/R/geom-smooth.r +++ b/R/geom-smooth.r @@ -91,7 +91,7 @@ geom_smooth <- function(mapping = NULL, data = NULL, ... ) if (identical(stat, "smooth")) { - params$method <- if (!is.null(method) && identical(method, "auto")) NULL else method + params$method <- method params$formula <- formula } diff --git a/R/stat-smooth.r b/R/stat-smooth.r index 669aca42fc..00e0101525 100644 --- a/R/stat-smooth.r +++ b/R/stat-smooth.r @@ -82,7 +82,7 @@ stat_smooth <- function(mapping = NULL, data = NULL, StatSmooth <- ggproto("StatSmooth", Stat, setup_params = function(data, params) { - msg <- NULL + msg <- character() if (is.null(params$method)) { # Use loess for small datasets, gam with a cubic regression basis for # larger. Based on size of the _largest_ group to avoid bad memory @@ -95,7 +95,7 @@ StatSmooth <- ggproto("StatSmooth", Stat, params$method <- "gam" } - msg <- paste0("`geom_smooth()` using method = '", params$method, "'") + msg <- c(msg, paste0("method = '", params$method, "'")) } if (is.null(params$formula)) { @@ -104,19 +104,15 @@ StatSmooth <- ggproto("StatSmooth", Stat, } else { y ~ x } - msg <- if (is.null(msg)) { - msg <- paste0("`geom_smooth()` using formula '", deparse(params$formula), "'") - } else { - msg <- paste0(msg, " and formula '", deparse(params$formula), "'") - } + msg <- c(msg, paste0("formula '", deparse(params$formula), "'")) } if (identical(params$method, "gam")) { params$method <- mgcv::gam } - if (!is.null(msg)) { - message(msg) + if (length(msg) > 0) { + message("`geom_smooth()` using ", paste0(msg, collapse = " and ")) } params From b4d92e71f1d6f1cde7cff28e1557343c419fc9cc Mon Sep 17 00:00:00 2001 From: Bernie Gray Date: Sat, 15 Jun 2019 22:01:28 -0400 Subject: [PATCH 10/12] fix backwards compatibility of method = 'auto' --- R/stat-smooth.r | 4 ++-- tests/testthat/test-geom-smooth.R | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/R/stat-smooth.r b/R/stat-smooth.r index 579f26dd4c..02b29c23d6 100644 --- a/R/stat-smooth.r +++ b/R/stat-smooth.r @@ -61,7 +61,7 @@ stat_smooth <- function(mapping = NULL, data = NULL, show.legend = show.legend, inherit.aes = inherit.aes, params = list( - method = if (!is.null(method) && identical(method, "auto")) NULL else method, + method = method, formula = formula, se = se, n = n, @@ -83,7 +83,7 @@ StatSmooth <- ggproto("StatSmooth", Stat, setup_params = function(data, params) { msg <- character() - if (is.null(params$method)) { + if (is.null(params$method) || identical(params$method, "auto")) { # Use loess for small datasets, gam with a cubic regression basis for # larger. Based on size of the _largest_ group to avoid bad memory # behaviour of loess diff --git a/tests/testthat/test-geom-smooth.R b/tests/testthat/test-geom-smooth.R index f7bce014f9..e3113d4ebe 100644 --- a/tests/testthat/test-geom-smooth.R +++ b/tests/testthat/test-geom-smooth.R @@ -48,6 +48,15 @@ test_that("default smoothing methods for small and large data sets work", { "method = 'gam' and formula 'y ~ s\\(x, bs = \"cs\"\\)" ) expect_equal(plot_data$y, as.numeric(out)) + + # backwards compatibility of method = "auto" + p <- ggplot(df, aes(x, y)) + geom_smooth(method = "auto") + + expect_message( + plot_data <- layer_data(p), + "method = 'gam' and formula 'y ~ s\\(x, bs = \"cs\"\\)" + ) + expect_equal(plot_data$y, as.numeric(out)) }) From 3aaa53ebfeb890b7192fe9a9b2da410b552ffc8d Mon Sep 17 00:00:00 2001 From: Bernie Gray Date: Sat, 15 Jun 2019 22:03:45 -0400 Subject: [PATCH 11/12] code aesthetics --- R/stat-smooth.r | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/stat-smooth.r b/R/stat-smooth.r index 02b29c23d6..ddf27e72ec 100644 --- a/R/stat-smooth.r +++ b/R/stat-smooth.r @@ -94,7 +94,6 @@ StatSmooth <- ggproto("StatSmooth", Stat, } else { params$method <- "gam" } - msg <- c(msg, paste0("method = '", params$method, "'")) } @@ -106,7 +105,6 @@ StatSmooth <- ggproto("StatSmooth", Stat, } msg <- c(msg, paste0("formula '", deparse(params$formula), "'")) } - if (identical(params$method, "gam")) { params$method <- mgcv::gam } From ca5ba90656ed276dd2efac1cd260c1c8b84bda36 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Mon, 30 Sep 2019 11:53:43 +0200 Subject: [PATCH 12/12] Fix styling --- R/stat-smooth.r | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/stat-smooth.r b/R/stat-smooth.r index ddf27e72ec..0bf34984c0 100644 --- a/R/stat-smooth.r +++ b/R/stat-smooth.r @@ -98,10 +98,10 @@ StatSmooth <- ggproto("StatSmooth", Stat, } if (is.null(params$formula)) { - params$formula <- if (identical(params$method, "gam")) { - y ~ s(x, bs = "cs") + if (identical(params$method, "gam")) { + params$formula <- y ~ s(x, bs = "cs") } else { - y ~ x + params$formula <- y ~ x } msg <- c(msg, paste0("formula '", deparse(params$formula), "'")) }