Skip to content

Commit 3626438

Browse files
committed
Trap error when trying to use formula function in random effect
1 parent 56b8f49 commit 3626438

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: nimbleMacros
2-
Version: 0.1.1
3-
Date: 2025-03-10
2+
Version: 0.1.1.9001
3+
Date: 2025-06-23
44
Title: Macros Generating 'nimble' Code
55
Authors@R: c(person("Ken", "Kellner", email="contact@kenkellner.com",
66
role=c("cre","aut")),

R/LINPRED.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ createRandomComponents <- function(formula){
370370
rand <- reformulas::findbars(formula)
371371
if(length(rand) == 0) return(NULL)
372372
components <- lapply(rand, function(x){
373+
if(grepl("(", safeDeparse(x), fixed=TRUE)){ # is this a function component?
374+
stop("Formula functions not supported in random effects", call.=FALSE)
375+
}
373376
out <- createBlankComponent("formulaComponentRandom")
374377
out$lang <- x
375378
out

tests/testthat/test_formulaHandlers.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ test_that("Error when function in formula is unsupported", {
1717
code <- quote(y[1:n] <- LINPRED(~x3 + test(x[1:10]), priors=NULL))
1818
expect_error(LINPRED$process(code, modelInfo=modInfo, .env=environment()), "No formula handler")
1919

20+
code <- quote(y[1:n] <- LINPRED(~x3 + (0 + scale(x3) | x2), priors=NULL))
21+
expect_error(LINPRED$process(code, modelInfo=modInfo, .env=environment()), "not supported in random effects")
2022
})
2123

2224
test_that("offset formula handler works", {

0 commit comments

Comments
 (0)