Skip to content

Commit

Permalink
Add an error message for issue #319.
Browse files Browse the repository at this point in the history
  • Loading branch information
fweber144 committed Mar 22, 2023
1 parent 9d649a2 commit f23a8b0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions R/formula.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extract_terms_response <- function(formula) {
hier <- grepl("\\|", terms_)
int <- grepl(":", terms_)
group_terms <- terms_[hier]
group_terms <- parse_group_terms(group_terms)
interaction_terms <- terms_[int & !hier]
individual_terms <- terms_[!hier & !int]
additive_terms <- parse_additive_terms(individual_terms)
Expand Down Expand Up @@ -92,6 +93,28 @@ extract_response <- function(response) {
return(response_name_ch)
}

# Parse group terms
#
# @param group_terms Character vector of group terms, but as extracted by
# labels(terms()), i.e., lacking the surrounding parentheses.
#
# @return Character vector of parsed group terms, but as extracted by
# labels(terms()), i.e., lacking the surrounding parentheses.
parse_group_terms <- function(group_terms) {
has_call <- sapply(strsplit(group_terms, "\\|"), function(grp_trm_split) {
if (length(grp_trm_split) != 2) {
stop("Unexpected number of `|` characters in group terms. Please ",
"contact the package maintainer.")
}
grepl("\\(", grp_trm_split[2])
})
if (any(has_call)) {
stop("Function calls on the right-hand side of a group-term `|` ",
"character are not allowed.")
}
return(group_terms)
}

## Parse additive terms (smooth terms) from a list of individual terms. See
## `?init_refmodel` for allowed smooth terms.
## @param terms list of terms to parse
Expand Down

0 comments on commit f23a8b0

Please sign in to comment.