Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vignette example doesn't run correctly without rjags #21

Closed
tbrown122387 opened this issue Nov 4, 2021 · 4 comments
Closed

vignette example doesn't run correctly without rjags #21

tbrown122387 opened this issue Nov 4, 2021 · 4 comments

Comments

@tbrown122387
Copy link

tbrown122387 commented Nov 4, 2021

The first example in the vignette does not work on my machine. The error seems to be MCMCdef_jags_impl(MCMCinfo, MCMCcontrol, monitorInfo, modelInfo) and it's complaining that run_jags: rjags package is required for 'jags' option. jags will not be run. Perhaps rjags has to be added as a dependency? If that's too extreme, maybe add a line in the vignette, or a commented out install.packages() call or something.

Edit: same issue with the second example in the vignette: rjags package is required for 'jags' option.

Also, I get a deprecation warning, and it's not immediately obvious on how to turn it off.

> make_MCMC_comparison_pages(res, modelName = 'example1')
Warning message:
`guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> = "none")` instead.`

Here's the full output, for posterity.

> library(compareMCMCs)
Loading required package: R6
Loading required package: nimble
nimble version 0.12.1 is loaded.
For more information on NIMBLE and a User Manual,
please visit https://R-nimble.org.

Attaching package: ‘nimble’

The following object is masked from ‘package:stats’:

    simulate

Loading required package: ggplot2
Loading required package: grid
Loading required package: reshape2
Loading required package: xtable

Attaching package: ‘compareMCMCs’

The following object is masked from ‘package:nimble’:

    compareMCMCs

> modelCode <- nimbleCode({
+   a ~ dunif(0, 100)
+   y ~ dgamma(a, 2)
+ })
> modelInfo <- list(
+   code = modelCode,
+   constants = list(y = 2),
+   inits = list(a = 1)
+ )
> configure_nimble_slice <- function(model) {
+   configureMCMC(model, onlySlice = TRUE)
+ }
> res <- compareMCMCs(modelInfo,
+                     MCMCs = c('jags', 'nimble', 'nimble_slice'),
+                     nimbleMCMCdefs = 
+                       list(nimble_slice = 'configure_nimble_slice'),
+                     MCMCcontrol = list(inits = list(a = 1),
+                                        niter = 2000,
+                                        burnin = 100))
building nimble model...
Defining model
  [Note] Using 'y' (given within 'constants') as data.
Building model
Setting data and initial values
Running calculate on model
  [Note] Any error reports that follow may simply reflect missing values in model variables.
Checking model sizes and dimensions
Error in MCMCdef_jags_impl(MCMCinfo, MCMCcontrol, monitorInfo, modelInfo) : 
  run_jags: rjags package is required for 'jags' option.  jags will not be run.

===== Monitors =====
thin = 1: a
===== Samplers =====
RW sampler (1)
  - a
===== Monitors =====
thin = 1: a
===== Samplers =====
slice sampler (1)
  - a
Compiling
  [Note] This may take a minute.
  [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
Compiling
  [Note] This may take a minute.
  [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
|-------------|-------------|-------------|-------------|
|-------------------------------------------------------|
|-------------|-------------|-------------|-------------|
|-------------------------------------------------------|
Warning message:
In compareMCMCs(modelInfo, MCMCs = c("jags", "nimble", "nimble_slice"),  :
  MCMC  jags  failed.

> make_MCMC_comparison_pages(res, modelName = 'example1')
Warning message:
`guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> = "none")` instead. 

openjournals/joss-reviews#3844

@tbrown122387 tbrown122387 changed the title vignette example doesn't run correctly vignette example doesn't run correctly without rjags Nov 4, 2021
@perrydv
Copy link
Collaborator

perrydv commented Jan 7, 2022

Hi @tbrown122387 I think this is fixed now. The vignette starts by checking if rjags and/or rstan are installed and only runs relevant code if they are. The deprecrated feature was something in ggplot2. We updated our code accordingly.

@tbrown122387
Copy link
Author

tbrown122387 commented Jan 8, 2022

Hey @perrydv I can get rid of "jags" from MCMCs=, but if I don't I get this when I re-run everything.

> library(compareMCMCs)
Loading required package: R6
Loading required package: nimble
nimble version 0.12.1 is loaded.
For more information on NIMBLE and a User Manual,
please visit https://R-nimble.org.

Attaching package: ‘nimble’

The following object is masked from ‘package:stats’:

    simulate

Loading required package: ggplot2
Loading required package: grid
Loading required package: reshape2
Loading required package: xtable

Attaching package: ‘compareMCMCs’

The following object is masked from ‘package:nimble’:

    compareMCMCs

> modelCode <- nimbleCode({
+   a ~ dunif(0, 100)
+   y ~ dgamma(a, 2)
+ })
> modelInfo <- list(
+   code = modelCode,
+   constants = list(y = 2),
+   inits = list(a = 1)
+ )
> configure_nimble_slice <- function(model) {
+   configureMCMC(model, onlySlice = TRUE)
+ }
> res <- compareMCMCs(modelInfo,
+                     MCMCs = c('jags', 'nimble', 'nimble_slice'),
+                     nimbleMCMCdefs = 
+                       list(nimble_slice = 'configure_nimble_slice'),
+                     MCMCcontrol = list(inits = list(a = 1),
+                                        niter = 2000,
+                                        burnin = 100))
building nimble model...
Defining model
  [Note] Using 'y' (given within 'constants') as data.
Building model
Setting data and initial values
Running calculate on model
  [Note] Any error reports that follow may simply reflect missing values in model variables.
Checking model sizes and dimensions
Error in MCMCdef_jags_impl(MCMCinfo, MCMCcontrol, monitorInfo, modelInfo) : 
  run_jags: rjags package is required for 'jags' option.  jags will not be run.

===== Monitors =====
thin = 1: a
===== Samplers =====
RW sampler (1)
  - a
===== Monitors =====
thin = 1: a
===== Samplers =====
slice sampler (1)
  - a
Compiling
  [Note] This may take a minute.
  [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
Compiling
  [Note] This may take a minute.
  [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
|-------------|-------------|-------------|-------------|
|-------------------------------------------------------|
|-------------|-------------|-------------|-------------|
|-------------------------------------------------------|
Warning message:
In compareMCMCs(modelInfo, MCMCs = c("jags", "nimble", "nimble_slice"),  :
  MCMC  jags  failed.

> make_MCMC_comparison_pages(res, modelName = 'example1')
Warning message:
`guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> = "none")` instead. 
> res_jags <- compareMCMCs(modelInfo,
+                 MCMCs = c('jags'),
+                 MCMCcontrol = list(inits = list(a = 1),
+                                    niter = 2000,
+                                    burnin = 100))
building nimble model...
Defining model
  [Note] Using 'y' (given within 'constants') as data.
Building model
Setting data and initial values
Running calculate on model
  [Note] Any error reports that follow may simply reflect missing values in model variables.
Checking model sizes and dimensions
Error in MCMCdef_jags_impl(MCMCinfo, MCMCcontrol, monitorInfo, modelInfo) : 
  run_jags: rjags package is required for 'jags' option.  jags will not be run.

Warning message:
In compareMCMCs(modelInfo, MCMCs = c("jags"), MCMCcontrol = list(inits = list(a = 1),  :
  MCMC  jags  failed.

> 

It's kind of weird because I have rjags installed

> which(grepl("rjags", installed.packages()))
[1] 123

I figured it was because I installed rjags but not JAGS, but apparently that's not true. Both installed without any warnings or errors, but library(rjags) yields this:

> library(rjags)
Error: package or namespace load failed for ‘rjags’:
 .onLoad failed in loadNamespace() for 'rjags', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rjags/libs/rjags.so':
  dlopen(/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rjags/libs/rjags.so, 10): Library not loaded: /usr/local/lib/libjags.4.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rjags/libs/rjags.so
  Reason: image not found

I don't even have the directory /Library/Frameworks/ so this is strange.

@perrydv
Copy link
Collaborator

perrydv commented Jan 8, 2022

Hi @tbrown122387 Thanks for trying this. I tried uninstalling rjags and I was still able to build the vignette cleanly without it. Is the output you're showing from running the vignette code directly (i.e. not knitting it)? If so, it looks like the errors are safe and accurate, saying that jags was not run. When building the vignette, a variable this_system_has_rjags prevents some code chunks from running at all, to avoid those (valid) errors. Also I no longer have the deprecation messages. Did you reinstall compareMCMCs from the joss branch? That's where I put the changes. I'll go ahead and move them to master. Finally I a wondering if the final error you're showing is entirely related to rjags and JAGS, not compareMCMCs? The JAGS installation is outside of R.

@tbrown122387
Copy link
Author

@perrydv yes you're right--my not having jags/rjags installed correctly on this machine has nothing to do with your work. The errors are indeed nonfatal/safe/best-case-scenario.

Regarding deprecation stuff, good call...that was fixed with git pull.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants