Skip to content

Commit

Permalink
Merge pull request #393 from fweber144/parse_additive_terms
Browse files Browse the repository at this point in the history
Error in case of non-predictor arguments of `s()` or `t2()`
  • Loading branch information
fweber144 authored Mar 6, 2023
2 parents 255a492 + c7e4005 commit 055a146
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions R/formula.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,21 @@ extract_response <- function(response) {
## @param terms list of terms to parse
## @return a vector of smooth terms
parse_additive_terms <- function(terms) {
excluded_terms <- c("te")
excluded_terms <- c("te", "ti")
smooth_terms <- c("s", "t2")
excluded <- unlist(sapply(excluded_terms, function(et) {
grep(make_function_regexp(et), terms)
excluded <- sapply(excluded_terms, function(et) {
any(grepl(make_function_regexp(et), terms))
})
if (any(excluded)) {
stop("te() and ti() terms are not supported, please use t2() instead.")
}
smooth <- unlist(lapply(smooth_terms, function(st) {
grep(make_function_regexp(st), terms, value = TRUE)
}))
if (sum(excluded) > 0) {
stop("te terms are not supported, please use t2 instead.")
if (any(grepl("\\(.+,.+=.+\\)", smooth))) {
stop("In s() and t2() terms, arguments other than predictors are not ",
"allowed.")
}
smooth <- unname(unlist(sapply(smooth_terms, function(et) {
terms[grep(make_function_regexp(et), terms)]
})))
return(smooth)
}

Expand Down

0 comments on commit 055a146

Please sign in to comment.