Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/nimble/R/genCpp_sizeProcessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/nimble/R/nimbleProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
8 changes: 8 additions & 0 deletions packages/nimble/tests/testthat/test-models.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading