Skip to content

Commit 8072fe3

Browse files
committed
Merge branch 'devel' of github.com:nimble-dev/nimble into devel
2 parents 140a994 + 4d1f8f3 commit 8072fe3

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

UserManual/src/tables/parameterizationTableLong.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ relationship to the *canonical* parameterization used in NIMBLE.
4747
`...shape, size)`
4848
`dnegbin(prob, size)` canonical
4949
`dnorm(mean, sd)` canonical
50-
`dnorm(mean, tau)` `dnorm(mean, sd = 1 / sqrt(var))`
50+
`dnorm(mean, tau)` `dnorm(mean, sd = 1 / sqrt(tau))`
5151
`dnorm(mean, var)` `dnorm(mean, sd = sqrt(var))`
5252
`dpois(lambda)` canonical
5353
`dt(mu, sigma, df)` canonical

packages/nimble/R/BUGS_macros.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ buildMacro <- function(fun,
198198
if(use3pieces) {
199199
wrapper <- function(code, modelInfo, .env) {
200200
args <- as.list(code)
201+
if(length(args) != 3){
202+
stop(paste0("buildMacro: This macro must be used as part of an assignment.\n",
203+
"Are you missing the left-hand-side of the assignment or assignment operator (~ / <-)?"),
204+
call.=FALSE)
205+
}
201206
args[[1]] <- args[[1]] == '~'
202207
names(args) <- c('stoch','LHS','RHS')
203208
if(unpackArgs) {

packages/nimble/tests/testthat/test-macros.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,37 @@ test_that("message given if same parameter is generated by macros multiple times
12711271
nimbleOptions(verbose = FALSE)
12721272
})
12731273

1274+
test_that("error when macro has use3pieces = TRUE but code is not an assignment", {
1275+
testMacro <- nimble:::buildMacro(
1276+
function(stoch, LHS, RHSarg, modelInfo, .env) {
1277+
ans <- substitute(
1278+
OP(LHS, dnorm(RHSarg, 1)),
1279+
list(LHS = LHS, RHSarg = RHSarg,
1280+
OP = if(stoch) as.name('~') else as.name('<-'))
1281+
)
1282+
list(code = ans, modelInfo=modelInfo)
1283+
},
1284+
use3pieces = TRUE, ## default
1285+
unpackArgs = TRUE ## default
1286+
)
1287+
1288+
# Code without LHS/assigment
1289+
code <- quote(testMacro(y[1]))
1290+
1291+
expect_error(
1292+
testMacro$process(code, modelInfo=list(), .env=environment()),
1293+
"This macro must be used as part of an assignment"
1294+
)
1295+
1296+
code <- quote(~testMacro(y[1]))
1297+
1298+
expect_error(
1299+
testMacro$process(code, modelInfo=list(), .env=environment()),
1300+
"This macro must be used as part of an assignment"
1301+
)
1302+
1303+
})
1304+
12741305
options(warn = RwarnLevel)
12751306
nimbleOptions(verbose = nimbleVerboseSetting)
12761307

0 commit comments

Comments
 (0)