Skip to content

Commit

Permalink
Merge pull request #394 from lucdw/master
Browse files Browse the repository at this point in the history
Change error/warnings if parser='c.r'
  • Loading branch information
yrosseel authored Nov 24, 2024
2 parents c8f9df0 + ae09a42 commit 84e9a91
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
29 changes: 15 additions & 14 deletions R/lav_syntax_parser_cr.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ ldw_parse_model_string_cr <- function(model.syntax = "",
tl[1L],
footer = tl[2L]
)
} else if (flat[1L] == 34L) { # SPE_INVALIDNAME
lav_msg_stop(gettext("a variable cannot be regressed on itself"),
tl[1L],
footer = tl[2L]
)
} else if (flat[1L] == 41L) { # SPE_INVALIDNAME
lav_msg_stop(gettext("identifier is either a reserved word (in R) or
contains an illegal character"),
Expand Down Expand Up @@ -126,6 +131,11 @@ ldw_parse_model_string_cr <- function(model.syntax = "",
tl[1L],
footer = tl[2L]
)
} else if (flat[1L] == 52L) { # SPE_LVLGRP
lav_msg_stop(gettext("groups can not be nested within levels!"),
tl[1L],
footer = tl[2L]
)
} else {
lav_msg_stop(gettext(
"internal error (code unknown) in lav_parse_model_string_cr!"))
Expand Down Expand Up @@ -203,24 +213,15 @@ ldw_parse_model_string_cr <- function(model.syntax = "",
tl[1L],
footer = tl[2L]
)
} else if (w[1L] == 105L) { # SPW_MODMULTIPLE
lav_msg_warn(gettext("syntax contains only a single block identifier!"),
tl[1L],
footer = tl[2L]
)
}
}
}

# new in 0.6-4: check for 'group' within 'level'
if (any(flat$op == ":")) {
op.idx <- which(flat$op == ":")
if (length(op.idx) < 2L) {
# only 1 block identifier? this is weird -> give warning
lav_msg_warn(gettext("syntax contains only a single block identifier!"))
} else {
first.block <- flat$lhs[op.idx[1L]]
second.block <- flat$lhs[op.idx[2L]]
if (first.block == "level" && second.block == "group") {
lav_msg_stop(gettext("groups can not be nested within levels!"))
}
}
}
if (as.data.frame.) {
flat <- as.data.frame(flat, stringsAsFactors = FALSE)
}
Expand Down
14 changes: 14 additions & 0 deletions R/lav_syntax_parser_r.R
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,20 @@ lav_parse_model_string_r <- function(model.syntax = "", as.data.frame. = FALSE)
}
}
}
# new in 0.6-4: check for 'group' within 'level'
if (any(flat$op == ":")) {
op.idx <- which(flat$op == ":")
if (length(op.idx) < 2L) {
# only 1 block identifier? this is weird -> give warning
lav_local_msgcode(FALSE, 105L, 1L, msgenv)
} else {
first.block <- flat$lhs[op.idx[1L]]
second.block <- flat$lhs[op.idx[2L]]
if (first.block == "level" && second.block == "group") {
return(c(52L, 1L))
}
}
}
# new in 0.6, reorder covariances here!
flat <- lav_partable_covariance_reorder(flat)
if (as.data.frame.) {
Expand Down

0 comments on commit 84e9a91

Please sign in to comment.