stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.04k stars 265 forks source link

Unable to assign output from paris.stanfit #1045

Open mikegilchrist opened 1 year ago

mikegilchrist commented 1 year ago

Summary:

Output from pairs.stanfit can only be directed to a device, it cannot be assigned to a variable. This ability is present in other implementation pairs() such as mcmc_pairs

Description:

When running pairs.stanfit() the returned object is eval(mc) where mc is of class call. As a result it can't be saved locally, but is displayed to the active device.

This behavior is different than, say, mcmc_pairs, whose output can be directed to a local variable.

Reproducible Steps:

library(rstan)
library(bayesplot)

example(read_stan_csv)

## rd_st_csvfiles <- dir(system.file('misc', package = 'rstan'),
## rd_st_+                 pattern = 'rstan_doc_ex_[0-9].csv', full.names = TRUE)
## rd_st_fit <- read_stan_csv(csvfiles)

stanfit_pairs_out <- pairs(fit, pars = c("mu", "sigma", "alpha", "lp__"), log = TRUE, las = 1)

## Warning in par(usr) : argument 1 does not name a graphical parameter
## Warning in par(usr) : argument 1 does not name a graphical parameter
## Warning in par(usr) : argument 1 does not name a graphical parameter
## Warning in par(usr) : argument 1 does not name a graphical parameter

class(stanfit_pairs_out)
## [1] "NULL" ## Current output

mcmc_out <- mcmc_pairs(fit, pars = c("mu", "sigma", "alpha", "lp__"))
class(mcmc_out) ## Expected output
## [1] "bayesplot_grid" "gtable"         "gTree"          "grob"
## [5] "gDesc"

RStan Version:

packageVersion("rstan")
## [1] ‘2.26.13’

R Version:

R.version.string
## [1] "R version 4.2.2 Patched (2022-11-10 r83330)"

Operating System:

MATE/Ubuntu 22.04