Skip to content

Commit f23a8b0

Browse files
committed
Add an error message for issue #319.
1 parent 9d649a2 commit f23a8b0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

R/formula.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extract_terms_response <- function(formula) {
2929
hier <- grepl("\\|", terms_)
3030
int <- grepl(":", terms_)
3131
group_terms <- terms_[hier]
32+
group_terms <- parse_group_terms(group_terms)
3233
interaction_terms <- terms_[int & !hier]
3334
individual_terms <- terms_[!hier & !int]
3435
additive_terms <- parse_additive_terms(individual_terms)
@@ -92,6 +93,28 @@ extract_response <- function(response) {
9293
return(response_name_ch)
9394
}
9495

96+
# Parse group terms
97+
#
98+
# @param group_terms Character vector of group terms, but as extracted by
99+
# labels(terms()), i.e., lacking the surrounding parentheses.
100+
#
101+
# @return Character vector of parsed group terms, but as extracted by
102+
# labels(terms()), i.e., lacking the surrounding parentheses.
103+
parse_group_terms <- function(group_terms) {
104+
has_call <- sapply(strsplit(group_terms, "\\|"), function(grp_trm_split) {
105+
if (length(grp_trm_split) != 2) {
106+
stop("Unexpected number of `|` characters in group terms. Please ",
107+
"contact the package maintainer.")
108+
}
109+
grepl("\\(", grp_trm_split[2])
110+
})
111+
if (any(has_call)) {
112+
stop("Function calls on the right-hand side of a group-term `|` ",
113+
"character are not allowed.")
114+
}
115+
return(group_terms)
116+
}
117+
95118
## Parse additive terms (smooth terms) from a list of individual terms. See
96119
## `?init_refmodel` for allowed smooth terms.
97120
## @param terms list of terms to parse

0 commit comments

Comments
 (0)