You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following script errors in a very confusing way:
library(rstan)
#================================================================================# Produce two dummy `stanfit` objectsmodel<-rstan::stan_model(model_code=r"( data { int<lower=0> N; array[N] int<lower=0, upper=1> y; } parameters { real<lower=0, upper=1> theta; } model { // uniform prior on interval 0,1 theta ~ beta(1, 1); y ~ bernoulli(theta); })")
data<-list(
a= round(runif(10, 0, 1)),
b= round(runif(15, 0, 1))
)
fits<- lapply(data, function(y) {
rstan::sampling(model, data=list(y=y, N= length(y)))
})
#================================================================================# Plot from within a closure:plot_function<-function() {
for (namein names(fits)) {
print(name) # Correctly prints "a".
pairs(fits[[name]], main=name)
}
}
pdf("test.pdf")
plot_function() # Error: object 'name' not found
dev.off()
From what I understand, pairs.stanfit, for some reason, does not evaluate its main = name argument within the context of the enclosing closure, but within the global scope instead. This was the source of a very nasty bug difficult to hunt down.
As far as I can check, this is not the expected/common behaviour of pair, and the problem does not happen, with, say:
The following script errors in a very confusing way:
From what I understand,
pairs.stanfit
, for some reason, does not evaluate itsmain = name
argument within the context of the enclosing closure, but within the global scope instead. This was the source of a very nasty bug difficult to hunt down.As far as I can check, this is not the expected/common behaviour of
pair
, and the problem does not happen, with, say:instead.
The text was updated successfully, but these errors were encountered: