diff --git a/packages/nimble/R/genCpp_sizeProcessing.R b/packages/nimble/R/genCpp_sizeProcessing.R index c0da0de9e..25a372559 100644 --- a/packages/nimble/R/genCpp_sizeProcessing.R +++ b/packages/nimble/R/genCpp_sizeProcessing.R @@ -2801,8 +2801,11 @@ sizeIndexingBracket <- function(code, symTab, typeEnv) { } next } else { ## not dropping a dimension, so the index is non-scalar - if(isExprClass) ## If it is an expression that is not `:` or blank, then a simple block is not allowed - if((code$args[[i+1]]$name != ':') && (code$args[[i+1]]$name != "")) simpleBlockOK <- FALSE + if(isExprClass) { ## If it is an expression that is not `:` or blank, then a simple block is not allowed + if(code$args[[i+1]]$name == '(') + stop("detected unexpected use of `(` in model code in `", safeDeparse(code$expr), "`. Parentheses cannot be used in indexing in NIMBLE models") + if((code$args[[i+1]]$name != ':') && (code$args[[i+1]]$name != "")) simpleBlockOK <- FALSE + } } needMap <- TRUE ## If the "next" in if(dropThisDim) {} is always hit, then needMap will never be set to TRUE diff --git a/packages/nimble/R/nimbleProject.R b/packages/nimble/R/nimbleProject.R index 690470696..01e0b6c9b 100644 --- a/packages/nimble/R/nimbleProject.R +++ b/packages/nimble/R/nimbleProject.R @@ -899,7 +899,7 @@ nimbleProjectClass <- setRefClass('nimbleProjectClass', ans <- nfCppDef$buildCallable(nf, dll = dll, asTopLevel = asTopLevel) ok <- !is.null(ans) } - if(!ok) stop("Oops, there is something in this compilation job that doesn\'t fit together. This can happen in some cases if you are trying to compile new pieces into an exising project. If that is the situation, please try including \"resetFunctions = TRUE\" as an argument to compileNimble. Alternatively please try rebuilding the project from the beginning with more pieces in the same call to compileNimble. For example, if you are compiling multiple algorithms for the same model in multiple calls to compileNimble, try compiling them all with one call.", call. = FALSE) + if(!ok) stop("There is something in this compilation job that doesn\'t fit together. This can happen in some cases if you are trying to compile new pieces into an existing project. If that is the situation, please try including \"resetFunctions = TRUE\" as an argument to compileNimble. Alternatively please try rebuilding the project from the beginning with more pieces in the same call to compileNimble. For example, if you are compiling multiple algorithms for the same model in multiple calls to compileNimble, try compiling them all with one call.", call. = FALSE) ans }, diff --git a/packages/nimble/tests/testthat/test-models.R b/packages/nimble/tests/testthat/test-models.R index 3bee70927..d60385a82 100644 --- a/packages/nimble/tests/testthat/test-models.R +++ b/packages/nimble/tests/testthat/test-models.R @@ -1026,6 +1026,14 @@ test_that("Warning printed when indexing info in user environment.", { "Information has been found in the user's environment") }) +test_that("Informative error when using parentheses with model indexing.", { + code <- nimbleCode({ + y[1,(1:2)] ~ ddirch(alpha[1:2]) + }) + m <- nimbleModel(code) + expect_error(cm <- compileNimble(m), "detected unexpected use of `\\(` in model code") +}) + options(warn = RwarnLevel) nimbleOptions(verbose = nimbleVerboseSetting)