suyusung / R2jags

R2jags: Using R to Run 'JAGS'
8 stars 3 forks source link

Error loading JAGS modules if `jags.module` is character(0) #12

Closed wlandau closed 3 years ago

wlandau commented 3 years ago

Thank you for reviewing and accepting my other pull requests.

One of the R2jags tests I wrote assigns jags.module = character(0) in jags(), and I just noticed this causes an error:

library(R2jags)
#> Loading required package: rjags
#> Loading required package: coda
#> Linked to JAGS 4.3.0
#> Loaded modules: basemod,bugs
#> 
#> Attaching package: 'R2jags'
#> The following object is masked from 'package:coda':
#> 
#>     traceplot
model <- "model {
  for (i in 1:n) {
    y[i] ~ dnorm(x[i] * beta, 1)
  }
  beta ~ dnorm(0, 1)
}"
tmp <- tempfile()
writeLines(model, tmp)
data <- list(
  n = 10,
  x = rnorm(10),
  y = rnorm(10)
)
library(coda)
out <- jags(
  data,
  parameters.to.save = "beta",
  model.file = tmp,
  n.chains = 4,
  DIC = FALSE,
  jags.module = character(0)
)
#> Error in load.module(jags.module[m], quiet = quiet): File not found: /usr/local/lib/JAGS/modules-4/NA.so

Created on 2021-08-04 by the reprex package (v2.0.0)

The error comes from these lines:

https://github.com/suyusung/R2jags/blob/4b767771af92147df428bc43d732475a4c710e7d/R/jags.R#L96-L101

It will be simple to fix, and I will submit a PR soon.