Skip to content

Commit 2728d98

Browse files
committed
Merge branch 'develop'
1 parent c670d3d commit 2728d98

37 files changed

+360
-248
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LICENSE
66
^README\.md$
77
.gitignore
88
^cran-comments\.md$
9+
^revdep$

.travis.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
language: r
22
sudo: required
3-
warnings_are_errors: false
3+
4+
cran: http://cran.rstudio.com/
5+
r_check_revdep: false
6+
pandoc: false
7+
8+
env:
9+
global:
10+
- _R_CHECK_FORCE_SUGGESTS_=false
411

512
r_binary_packages:
6-
- reshape2
13+
- coda
14+
- dygraphs
715
- ggplot2
8-
- jsonlite
9-
- Rcpp
1016
- gtools
11-
- markdown
17+
- httpuv
18+
- inline
19+
- jsonlite
1220
- knitr
21+
- markdown
22+
- reshape2
23+
- Rcpp
24+
- RUnit
25+
- shiny
26+
- testthat
1327
- xts
14-
15-
env:
16-
global:
17-
- _R_CHECK_FORCE_SUGGESTS_=false
28+
- yaml
1829

1930
notifications:
2031
email:

DESCRIPTION

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: shinystan
22
Title: Interactive Visual and Numerical Diagnostics and Posterior Analysis for Bayesian Models
3-
Version: 2.0.0
4-
Date: 2015-08-09
3+
Version: 2.0.1
4+
Date: 2015-09-17
55
Authors@R: c(person("Jonah", "Gabry", role = c("aut", "cre"),
66
email = "[email protected]"),
77
person(family = "Stan Development Team", role = "ctb"),
@@ -25,7 +25,6 @@ URL: https://github.com/stan-dev/shinystan, http://mc-stan.org/
2525
BugReports: https://github.com/stan-dev/shinystan/issues
2626
Depends:
2727
R (>= 3.1.0),
28-
ggplot2 (>= 1.0.0),
2928
shiny (>= 0.12.1)
3029
License: GPL (>=3)
3130
LazyData: true
@@ -37,16 +36,17 @@ Suggests:
3736
Imports:
3837
DT (>= 0.1),
3938
dygraphs (>= 0.4.5),
39+
ggplot2 (>= 1.0.0),
4040
gridExtra,
4141
gtools,
4242
markdown (>= 0.7.4),
4343
methods,
4444
reshape2,
4545
stats,
46-
shinyjs (>= 0.0.7.0),
46+
shinyjs (>= 0.1.0),
4747
shinythemes (>= 1.0.1),
4848
threejs (>= 0.2.1),
4949
utils,
50-
xtable (>= 1.7-4),
50+
xtable,
5151
xts (>= 0.9-7)
5252
VignetteBuilder: knitr

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ importFrom(shinyjs,colourInput)
2828
importFrom(shinyjs,useShinyjs)
2929
importFrom(shinythemes,shinytheme)
3030
importFrom(stats,acf)
31+
importFrom(stats,model.frame)
32+
importFrom(stats,model.response)
3133
importFrom(stats,quantile)
3234
importFrom(stats,time)
3335
importFrom(stats,var)

NEWS.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
## ShinyStan version 2.0.0 (major update)
1+
# `shinystan news`
2+
3+
### Version 2.0.1
4+
* Fixes small bugs and typos
5+
* Adds support for stanreg objects
6+
* Moves ggplot2 from Depends to Imports
7+
8+
### Version 2.0.0 (major update)
29

310
Version 2.0.0 has a new look, a new(ish) name, and a lot of new functionality.
411
Many bugs have also been fixed (see GitHub issue tracker).
512

613
It's also now [available on CRAN](https://cran.rstudio.com/web/packages/shinystan/index.html).
714

8-
### Names
15+
### New names
916
* The name of the R package is **shinystan** and the app/GUI is **ShinyStan**.
1017

1118
### Deploy ShinyStan apps to shinyapps.io (RStudio's ShinyApps service)

R/deploy_shinystan.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,18 @@ deploy_shinystan <- function(sso, appName, account = NULL, ...) {
8181
file_name <- file.path(deployDir, paste0(ff, ".R"))
8282
fconn <- file(file_name, 'r+')
8383
original_content <- readLines(fconn)
84+
if (ff %in% c("ui", "server")) {
85+
sel <- grep(".shinystan_temp_object", original_content)
86+
original_content <- original_content[-sel]
87+
}
8488
new_lines <- get(paste0(ff, "_lines"))
8589
writeLines(c(new_lines, original_content), con = fconn)
8690
close(fconn)
8791
}
8892

8993
# save shinystan_object to deployDir
90-
.shinystan_temp_object <- sso
91-
save(.shinystan_temp_object,
92-
file = file.path(deployDir, "shinystan_temp_object.RData"))
94+
object <- sso
95+
save(object, file = file.path(deployDir, "shinystan_temp_object.RData"))
9396
deploy <- getFromNamespace("deployApp", "shinyapps")
9497
# save ppcheck_data and set ppcheck defaults
9598
pp <- list(...)

R/launch_shinystan.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,15 @@ launch_shinystan <- function(object, rstudio = getOption("shinystan.rstudio"),
7474
name <- deparse(substitute(object))
7575
no_name <- substr(name, 1, 12) == "as.shinystan"
7676
if (missing(object))
77-
stop("Please specify a shinystan or stanfit object.")
77+
stop("Please specify a shinystan or stanfit object.", call. = FALSE)
7878
message("\nLoading... \n",
7979
"Note: for large models ShinyStan may take a few moments to launch.")
8080

8181
if (inherits(object, "stanreg"))
82-
object <- object$stanfit
82+
object <- stanreg2shinystan(object)
8383
if (inherits(object, "stanfit"))
8484
object <- stan2shinystan(object)
8585
if (!is.shinystan(object))
8686
stop(paste(name, "is not a valid input. See ?launch_shinystan"))
87-
on.exit(cleanup_shinystan())
8887
invisible(launch(object, rstudio, ...))
8988
}

R/launch_shinystan_demo.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@
4040
launch_shinystan_demo <- function(rstudio = getOption("shinystan.rstudio"),
4141
...) {
4242
demo_name <- "eight_schools"
43-
on.exit(cleanup_shinystan())
4443
invisible(launch(get(demo_name), rstudio, ...))
4544
}

R/misc.R

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ sso_check <- function(sso) {
1919
else
2020
invisible(TRUE)
2121
}
22-
is_stan <- function(X) {
23-
inherits(X, "stanfit")
24-
}
22+
is.stanfit <- function(X) inherits(X, "stanfit")
23+
is.stanreg <- function(X) inherits(X, "stanreg")
24+
2525
rstan_check <- function() {
2626
if (!requireNamespace("rstan", quietly = TRUE))
2727
stop("You need to have the RStan package installed to use this option.",
@@ -32,15 +32,13 @@ coda_check <- function() {
3232
stop("You need to have the coda package installed to use this option.",
3333
call. = FALSE)
3434
}
35-
cleanup_shinystan <- function() {
36-
rm(list = ".shinystan_temp_object", envir = .GlobalEnv)
37-
}
3835

3936
launch <- function(object, rstudio = FALSE, ...) {
4037
stopifnot(is.shinystan(object))
4138
launch.browser <- if (!rstudio)
4239
TRUE else getOption("shiny.launch.browser", interactive())
43-
assign(".shinystan_temp_object", object, inherits = TRUE)
40+
.sso_env$.shinystan_temp_object <- object
41+
on.exit(.sso_env$.shinystan_temp_object <- NULL, add = TRUE)
4442
shiny::runApp(system.file("ShinyStan", package = "shinystan"),
4543
launch.browser = launch.browser, ...)
4644
}
@@ -65,10 +63,10 @@ grepl_ic <- function(pattern, x, ignore.case = TRUE) {
6563

6664
get_type <- function(x) {
6765
if (is.shinystan(x)) return("shinystan")
68-
else if (is_stan(x)) return("stanfit")
66+
else if (is.stanfit(x)) return("stanfit")
67+
else if (is.stanreg(x)) return("stanreg")
6968
else if (inherits(x, "mcmc.list")) return("mcmclist")
70-
else if (is.list(x) & !inherits(x, "mcmc.list")) return("chainlist")
71-
else if (inherits(x, "stanreg")) return("stanreg")
69+
else if (is.list(x)) return("chainlist")
7270
else return("other")
7371
}
7472

R/stan2shinystan.R

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,75 @@
1313
# You should have received a copy of the GNU General Public License along with
1414
# this program; if not, see <http://www.gnu.org/licenses/>.
1515

16+
17+
.rename_scalar <- function(sso, oldname = "lp__", newname = "log-posterior") {
18+
p <- which(sso@param_names == oldname)
19+
if (identical(integer(0), p))
20+
return(sso)
21+
sso@param_names[p] <-
22+
dimnames(sso@samps_all)$parameters[p] <-
23+
names(sso@param_dims)[which(names(sso@param_dims) == oldname)] <- newname
24+
sso
25+
}
26+
1627
# convert stanfit object to shinystan object
1728
stan2shinystan <- function(stanfit, model_name, notes) {
1829
# notes: text to add to user_model_info slot
1930
rstan_check()
20-
if (!inherits(stanfit, "stanfit")) {
31+
if (!is.stanfit(stanfit)) {
2132
name <- deparse(substitute(stanfit))
2233
stop(paste(name, "is not a stanfit object."))
2334
}
2435

25-
stan_args <- stanfit@stan_args[[1]]
36+
stan_args <- stanfit@stan_args[[1L]]
37+
stan_method <- stan_args$method
38+
vb <- stan_method == "variational"
2639
from_cmdstan_csv <- ("engine" %in% names(stan_args))
2740
stan_algorithm <- if (from_cmdstan_csv)
2841
toupper(stan_args$engine) else stan_args$algorithm
2942
warmup <- if (from_cmdstan_csv) stanfit@sim$warmup2[1L] else stanfit@sim$warmup
3043
nWarmup <- if (from_cmdstan_csv) warmup else floor(warmup / stanfit@sim$thin)
3144

32-
max_td <- stanfit@stan_args[[1]]$control
33-
if (is.null(max_td))
45+
cntrl <- stanfit@stan_args[[1L]]$control
46+
if (is.null(cntrl))
3447
max_td <- 11
3548
else {
36-
max_td <- max_td$max_treedepth
49+
max_td <- cntrl$max_treedepth
3750
if (is.null(max_td))
3851
max_td <- 11
3952
}
4053

4154
samps_all <- rstan::extract(stanfit, permuted = FALSE, inc_warmup = TRUE)
42-
param_names <- dimnames(samps_all)[[3]] # stanfit@sim$fnames_oi
55+
param_names <- dimnames(samps_all)[[3L]] # stanfit@sim$fnames_oi
4356
param_dims <- stanfit@sim$dims_oi
4457

45-
if (!(stan_algorithm %in% c("NUTS", "HMC"))) {
46-
warning("Most shinyStan features are only available for models using
58+
if (!vb && !(stan_algorithm %in% c("NUTS", "HMC"))) {
59+
warning("Most features are only available for models using
4760
algorithm NUTS or algorithm HMC.")
4861
}
49-
5062
mname <- if (!missing(model_name)) model_name else stanfit@model_name
5163
mcode <- rstan::get_stancode(stanfit)
5264

65+
sampler_params <- if (vb) list(NA) else rstan::get_sampler_params(stanfit)
66+
stan_summary <- rstan::summary(stanfit)$summary
67+
if (vb) stan_summary <- cbind(stan_summary, Rhat = NA, n_eff = NA, se_mean = NA)
68+
5369
slots <- list()
5470
slots$Class <- "shinystan"
5571
slots$model_name <- mname
5672
slots$param_names <- param_names
5773
slots$param_dims <- param_dims
5874
slots$samps_all <- samps_all
59-
slots$summary <- rstan::summary(stanfit)$summary
60-
slots$sampler_params <- rstan::get_sampler_params(stanfit)
75+
slots$summary <- stan_summary
76+
slots$sampler_params <- sampler_params
6177
slots$nChains <- ncol(stanfit)
6278
slots$nIter <- nrow(samps_all)
6379
slots$nWarmup <- nWarmup
6480
if (!missing(notes)) slots$user_model_info <- notes
6581
if (length(mcode) > 0) slots$model_code <- mcode
66-
slots$misc <- list(max_td = max_td, stan_algorithm = stan_algorithm)
67-
do.call("new", slots)
82+
slots$misc <- list(max_td = max_td, stan_method = stan_method,
83+
stan_algorithm = stan_algorithm)
84+
sso <- do.call("new", slots)
85+
.rename_scalar(sso)
6886
}
87+

0 commit comments

Comments
 (0)