@@ -814,9 +814,14 @@ ldw_parse_model_string <- function(model.syntax = "", as.data.frame. = FALSE) {
814
814
}
815
815
nelem <- length(formul1 $ elem.type )
816
816
# where is the operator
817
- opi <- match(types $ lavaanoperator , formul1 $ elem.type )
818
- # opi <- which(formul1$elem.type == types$lavaanoperator)
819
- # if (length(opi) > 1L) opi <- opi[1L]
817
+ opi <- which(formul1 $ elem.type == types $ lavaanoperator )
818
+ if (length(opi ) > 1L ) { # if more then 1 operator skip operators ':'
819
+ opii <- 1L
820
+ while (formul1 $ elem.text [opi [opii ]] == " :" && opii < length(opi )) {
821
+ opii <- opii + 1L
822
+ }
823
+ opi <- opi [opii ]
824
+ }
820
825
op <- formul1 $ elem.text [opi ]
821
826
if (any(op == constraint_operators )) { # ----- constraints -------
822
827
lhs <- paste(formul1 $ elem.text [seq.int(1L , opi - 1L )], collapse = " " )
@@ -953,7 +958,8 @@ ldw_parse_model_string <- function(model.syntax = "", as.data.frame. = FALSE) {
953
958
colons <- which(formul1 $ elem.text [seq.int(1L , nelem - 1L )] == " :" &
954
959
formul1 $ elem.type [seq.int(2L , nelem )] == types $ identifier )
955
960
# check at most 1 colon
956
- if (length(colons ) > 1 ) {
961
+ if (length(colons ) > 2L ||
962
+ (length(colons ) == 2L && (colons [1L ] > opi || colons [2L ] < opi ))) {
957
963
tl <- ldw_txtloc(modelsrc , formul1 $ elem.pos [colons [2 ]])
958
964
lav_msg_stop(
959
965
gettext(
@@ -965,13 +971,28 @@ ldw_parse_model_string <- function(model.syntax = "", as.data.frame. = FALSE) {
965
971
), tl [1L ], footer = tl [2L ]
966
972
)
967
973
}
968
- if (length(colons ) == 1 ) {
974
+ if (length(colons ) > 0L ) {
969
975
# collapse items around colon "a" ":" "b" => "a:b"
970
- formul1 $ elem.text [colons - 1L ] <-
971
- paste(formul1 $ elem.text [seq.int(colons - 1L , colons + 1L )],
976
+ formul1 $ elem.text [colons [ 1L ] - 1L ] <-
977
+ paste(formul1 $ elem.text [seq.int(colons [ 1L ] - 1L , colons [ 1L ] + 1L )],
972
978
collapse = " "
973
979
)
974
- formul1 <- ldw_parse_sublist(formul1 , seq.int(1L , colons - 1L ))
980
+ formul1 <- ldw_parse_sublist(formul1 ,
981
+ setdiff(seq.int(1L , nelem ), seq.int(colons [1L ], colons [1L ] + 1L )))
982
+ nelem <- length(formul1 $ elem.type )
983
+ if (colons [1L ] < opi ) {
984
+ opi <- opi - 2L # is in LHS
985
+ if (length(colons ) == 2L ) colons [2L ] <- colons [2L ] - 2L
986
+ }
987
+ }
988
+ if (length(colons ) == 2L ) {
989
+ # collapse items around colon "a" ":" "b" => "a:b"
990
+ formul1 $ elem.text [colons [2L ] - 1L ] <-
991
+ paste(formul1 $ elem.text [seq.int(colons [2L ] - 1L , colons [2L ] + 1L )],
992
+ collapse = " "
993
+ )
994
+ formul1 <- ldw_parse_sublist(formul1 ,
995
+ setdiff(seq.int(1L , nelem ), seq.int(colons [2L ], colons [2L ] + 1L )))
975
996
nelem <- length(formul1 $ elem.type )
976
997
}
977
998
# modifiers
0 commit comments