diff --git a/R/lav_syntax_parser.R b/R/lav_syntax_parser.R index a7b30a0a..a1f0b5d8 100644 --- a/R/lav_syntax_parser.R +++ b/R/lav_syntax_parser.R @@ -903,15 +903,6 @@ ldw_parse_model_string <- function(model.syntax = "", as.data.frame. = FALSE) { footer = tl[2L] ) } - # check for variable regressed on itself - if (formul1$elem.text[opi] == "~" && formul1$elem.text[opi - 1L] == formul1$elem.text[nelem]) { - tl <- ldw_txtloc(modelsrc, formul1$elem.pos[opi]) - lav_msg_stop( - gettext("a variable cannot be regressed on itself"), - tl[1L], - footer = tl[2L] - ) - } # checks for valid names in lhs and rhs ldw_parse_check_valid_name(formul1, opi - 1L, modelsrc) # valid name lhs for (j in seq.int(opi + 1L, nelem)) { # valid names rhs @@ -1101,6 +1092,18 @@ ldw_parse_model_string <- function(model.syntax = "", as.data.frame. = FALSE) { } } } + # check for variable regressed on itself + if (formul1$elem.text[opi] == "~" && + formul1$elem.text[opi - 1L] == formul1$elem.text[nelem]) { + if (!grepl("^0\\.?0*$", flat.fixed[idx])) { + tl <- ldw_txtloc(modelsrc, formul1$elem.pos[opi]) + lav_msg_stop( + gettext("a variable cannot be regressed on itself"), + tl[1L], + footer = tl[2L] + ) + } + } } # create flat (omit items without operator) filled.ones <- which(flat.op != "") diff --git a/R/lav_syntax_parser_r.R b/R/lav_syntax_parser_r.R index 43c6fd8a..f7ef1811 100644 --- a/R/lav_syntax_parser_r.R +++ b/R/lav_syntax_parser_r.R @@ -797,9 +797,6 @@ lav_parse_model_string_r <- function(model.syntax = "", as.data.frame. = FALSE) if (length(contsp) > 0L) { lav_local_msgcode(FALSE, 102L, formul1$elem.pos[contsp[1L]], msgenv) } - # check for variable regressed on itself - if (formul1$elem.text[opi] == "~" && formul1$elem.text[opi - 1L] == formul1$elem.text[nelem]) - return(c(34L, formul1$elem.pos[opi] - 1L)) # checks for valid names in lhs and rhs lav_parse_check_valid_name(formul1, opi - 1L, modelsrc, msgenv) # valid name lhs if (exists("error", envir = msgenv)) return(msgenv$error); @@ -969,6 +966,10 @@ lav_parse_model_string_r <- function(model.syntax = "", as.data.frame. = FALSE) } } } + # check for variable regressed on itself + if (formul1$elem.text[opi] == "~" && + formul1$elem.text[opi - 1L] == formul1$elem.text[nelem]) + if (!grepl("^0\\.?0*$", flat.fixed[idx])) return(c(34L, formul1$elem.pos[opi] - 1L)) } # create flat (omit items without operator) filled.ones <- which(flat.op != "")