Skip to content

Commit bcd5027

Browse files
committed
check (and warn) for duplicated defined variables (using the := operator)
1 parent 8ecb469 commit bcd5027

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: lavaan
22
Title: Latent Variable Analysis
3-
Version: 0.6-20.2332
3+
Version: 0.6-20.2333
44
Authors@R: c(person(given = "Yves", family = "Rosseel",
55
role = c("aut", "cre"),
66
email = "Yves.Rosseel@UGent.be",

R/lav_partable.R

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,22 @@ lavaanify <- lavParTable <- function(
903903
}
904904
}
905905

906-
# put lhs of := elements in label column
906+
# check defined variables (:=)
907907
def.idx <- which(tmp.list$op == ":=")
908-
tmp.list$label[def.idx] <- tmp.list$lhs[def.idx]
908+
if (length(def.idx) > 0L) {
909+
# check if the lhs is unique (new in 0.6-20)
910+
def.lhs <- tmp.list$lhs[def.idx]
911+
dup.idx <- which(duplicated(def.lhs))
912+
if (length(dup.idx) > 0L) {
913+
# warn or stop? warn for now
914+
lav_msg_warn(gettextf("at least one defined variable (using the :=
915+
operator) has been duplicated, and will be
916+
overwritten by the last one: %s",
917+
paste(def.lhs[dup.idx], collapse = " ")))
918+
}
919+
# put lhs of := elements in label column
920+
tmp.list$label[def.idx] <- def.lhs
921+
}
909922

910923

911924
# handle effect.coding related equality constraints

0 commit comments

Comments
 (0)