From 1c7f4b8fc89a554b2bff9349810efea40973550b Mon Sep 17 00:00:00 2001 From: Gavin Simpson Date: Wed, 6 Jul 2022 17:09:45 +0200 Subject: [PATCH] derivatives will now ignore random effect smooths: fixes #168 --- R/derivatives.R | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/R/derivatives.R b/R/derivatives.R index 8c4901124..ee40e956b 100644 --- a/R/derivatives.R +++ b/R/derivatives.R @@ -58,6 +58,9 @@ #' with `term`? If `TRUE`, `term` can only be a single string to match #' against. #' +#' @note `derivatives()` will ignore any random effect smooths it encounters in +#' `object`. +#' #' @export #' #' @importFrom dplyr filter @@ -105,12 +108,20 @@ partial_match = FALSE, ...) { ## handle term smooth_ids <- if (!missing(term)) { - ## which smooths match 'term' - sms <- check_user_select_smooths(smooths(object), term, - partial_match = partial_match) - which(sms) + ## which smooths match 'term' + sms <- check_user_select_smooths(smooths(object), term, + partial_match = partial_match) + ## need to skip random effect smooths + take <- vapply(object$smooth[sms], smooth_type , character(1)) %in% + "Random effect" + sms[take] <- FALSE + which(sms) } else { - seq_len(n_smooths(object)) + s <- seq_len(n_smooths(object)) + ## need to skip random effect smooths + take <- vapply(object$smooth, smooth_type, + character(1)) %in% "Random effect" + s[!take] } ## handle type