Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in case of non-predictor arguments of s() or t2() #393

Merged
merged 5 commits into from
Mar 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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