Hi Matthijs,
I'll give a brief overview of the steps that would generally be involved. Beyond that, I agree that having a detailed template/example would be helpful. We're in the middle of preparing for our virtual workshop next week, and this is a nice example for that, so I'm hoping to have something more concrete to share in coming days.
The following assumes that you want to simulate new datasets given the posterior samples of the model parameters.
Basic steps:
1) run the MCMC, making sure to monitor nodes that are parents of the data nodes (this could be all stochastic+deterministic direct parents or all stochastic parents, basically whatever you need to be able to simulate the data nodes from the posterior predictive)
2) With the MCMC output (either as a matrix or as the mvSamples object of the compiled MCMC), loop through the saved samples and:
a) Put the saved sample from a given iteration into the model
b) Simulate into the data nodes (you'll need to specify 'includeData = TRUE' when calling 'simulate')
c) Save the values of the simulated data nodes (for example, to a row of an output matrix)
3) carry out whatever assessment you want on the posterior predictive samples
Step 2 could be done (a) fully in R (including using an uncompiled model), (b) partly in R (using a compiled model, but otherwise done from R), or (c) fully in a compiled nimbleFunction that you create to carry out Steps 2a-2c.
-chris