@@ -29,6 +29,7 @@ extract_terms_response <- function(formula) {
29
29
hier <- grepl(" \\ |" , terms_ )
30
30
int <- grepl(" :" , terms_ )
31
31
group_terms <- terms_ [hier ]
32
+ group_terms <- parse_group_terms(group_terms )
32
33
interaction_terms <- terms_ [int & ! hier ]
33
34
individual_terms <- terms_ [! hier & ! int ]
34
35
additive_terms <- parse_additive_terms(individual_terms )
@@ -92,6 +93,28 @@ extract_response <- function(response) {
92
93
return (response_name_ch )
93
94
}
94
95
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
+
95
118
# # Parse additive terms (smooth terms) from a list of individual terms. See
96
119
# # `?init_refmodel` for allowed smooth terms.
97
120
# # @param terms list of terms to parse
0 commit comments