Skip to content

Commit

Permalink
Fix cov <- NULL and cov ~ NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Sep 7, 2024
1 parent 3e491c2 commit bd88b75
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions R/piping-ini.R
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,12 @@
# downstream operations
expr <- .iniSimplifyAssignArrow(expr)

if (.matchesLangTemplate(expr, str2lang(".name <- NULL"))) {
expr <- as.call(list(quote(`-`), expr[[2]]))
} else if (.matchesLangTemplate(expr, str2lang(".name ~ NULL"))) {
if (.matchesLangTemplate(expr, str2lang(".name <- NULL")) ||
.matchesLangTemplate(expr, str2lang(".name ~ NULL")) ||
.matchesLangTemplate(expr, str2lang("cov(.name, .name) <- NULL")) ||
.matchesLangTemplate(expr, str2lang("cor(.name, .name) <- NULL")) ||
.matchesLangTemplate(expr, str2lang("cov(.name, .name) ~ NULL")) ||
.matchesLangTemplate(expr, str2lang("cor(.name, .name) ~ NULL"))) {
expr <- as.call(list(quote(`-`), expr[[2]]))
}

Expand Down
2 changes: 1 addition & 1 deletion R/piping.R
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@
} else if (identical(.quoted[[1]], quote(`as.formula`))) {
.quoted <- .quoted[[2]]
} else if (identical(.quoted[[1]], quote(`~`))) {
if (length(.quoted) == 3L) {
if (length(.quoted) == 3L && !is.null(.quoted[[3]])) {
.quoted[[3]] <- .iniSimplifyFixUnfix(.quoted[[3]])
if (identical(.quoted[[3]], quote(`fix`)) ||
identical(.quoted[[3]], quote(`unfix`))) {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-piping-ini.R
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ test_that("ini(diag) and ini(-cov()) tests", {
}))

tmp <- mod2 %>% ini(cor(lcl, lvc) <- NULL)

expect_equal(tmp$omega,
lotri({
lvc ~ 3.45
Expand Down

0 comments on commit bd88b75

Please sign in to comment.