Skip to content

Commit

Permalink
fixes for CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabry committed Mar 30, 2021
1 parent bc131bf commit f11d054
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ LICENSE
^\.travis\.yml$
^README\.md$
.gitignore
.github/*
^cran-comments\.md$
^revdep$
man-roxygen/*
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: shinystan
Title: Interactive Visual and Numerical Diagnostics and Posterior Analysis for
Bayesian Models
Version: 2.5.0
Date: 2018-04-29
Version: 2.6.0
Date: 2021-03-30
Authors@R: c(person("Jonah", "Gabry", role = c("aut", "cre"),
email = "[email protected]"),
person(family = "Stan Development Team", role = "ctb"),
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ importFrom(gridExtra,grid.arrange)
importFrom(gtools,mixedsort)
importFrom(markdown,markdownToHTML)
importFrom(reshape2,melt)
importFrom(rsconnect,deployApp)
importFrom(shinyjs,useShinyjs)
importFrom(shinythemes,shinytheme)
importFrom(stats,acf)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# shinystan 2.6.0

* Moved rsconnect package from Imports to Suggests as requested by CRAN
* Initial support for CmdStanMCMC objects from CmdStanR

# shinystan 2.5.0

* New website with online documentation: http://mc-stan.org/shinystan
Expand Down
7 changes: 4 additions & 3 deletions R/deploy_shinystan.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#'
#' \url{http://www.shinyapps.io/} to sign up for a free or paid 'ShinyApps'
#' account and for details on how to configure your account on your local
#' system using the \pkg{\link[rsconnect]{rsconnect}} package from 'RStudio'.
#' system using the \pkg{rsconnect} package from 'RStudio'.
#'
#' @examples
#' \dontrun{
Expand All @@ -64,8 +64,6 @@
#' deploy_shinystan(sso, appName = "my-model")
#' }
#'
#' @importFrom rsconnect deployApp
#'
deploy_shinystan <- function(sso, appName, account = NULL, ..., deploy = TRUE) {
sso_check(sso)
if (missing(appName))
Expand Down Expand Up @@ -133,6 +131,9 @@ deploy_shinystan <- function(sso, appName, account = NULL, ..., deploy = TRUE) {
if (!deploy)
return(invisible(deployDir))

if (!requireNamespace("rsconnect", quietly = TRUE)) {
stop("Please install the 'rsconnect' package.", call. = FALSE)
}
rsconnect::deployApp(
appDir = deployDir,
appName = appName,
Expand Down
2 changes: 1 addition & 1 deletion R/shinystan-objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ setMethod(
note = note,
sampler_params = sampler_params,
algorithm = "NUTS",
max_treedepth = fit$metadata()$max_treedepth
max_treedepth = X$metadata()$max_treedepth
)
}
)
Binary file modified data/eight_schools.rda
Binary file not shown.
12 changes: 6 additions & 6 deletions man/as.shinystan.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/deploy_shinystan.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions tests/testthat/test_creating_sso.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
library(shinystan)
suppressPackageStartupMessages(library(rstan))
suppressPackageStartupMessages(library(rstanarm))
library(coda)
suppressPackageStartupMessages(library(rstan))

sso <- eight_schools
array1 <- array(rnorm(300), dim = c(25, 4, 3))
Expand All @@ -13,11 +12,15 @@ data(line, package = "coda")
mcmc1 <- line
mcmc2 <- line[[1L]]

suppressWarnings(capture.output(
stanreg1 <- stan_glmer(mpg ~ wt + (1 + wt|cyl), data = mtcars,
seed = 12345, iter = 200, chains = 2, refresh = 0)
))
stanfit1 <- stanreg1$stanfit
if (requireNamespace("rstanarm", quietly = TRUE)) {
suppressPackageStartupMessages(library(rstanarm))
suppressWarnings(capture.output(
stanreg1 <- stan_glmer(mpg ~ wt + (1 + wt|cyl), data = mtcars,
seed = 12345, iter = 200, chains = 2, refresh = 0)
))
stanfit1 <- stanreg1$stanfit
}


# load 'old_sso', a shinystan object created by previous shinystan version
load("old_sso_for_tests.rda")
Expand All @@ -39,6 +42,7 @@ test_that("sso_check throws errors", {

# is.shinystan ------------------------------------------------------------
test_that("is.shinystan, is.stanfit, is.stanreg work", {
skip_if_not_installed("rstanarm")
expect_true(is.shinystan(sso))
expect_false(is.shinystan(sso@posterior_sample))

Expand All @@ -53,6 +57,7 @@ test_that("is.shinystan, is.stanfit, is.stanreg work", {
context("Creating shinystan objects")
# as.shinystan helpers ----------------------------------------------------
test_that("as.shinystan stanfit helpers work", {
skip_if_not_installed("rstanarm")
expect_is(.rstan_max_treedepth(stanfit1), "integer")
expect_equal(.rstan_warmup(stanfit1), 0)
expect_equal(length(.rstan_sampler_params(stanfit1)), ncol(stanfit1))
Expand All @@ -68,7 +73,7 @@ test_that("as.shinystan stanfit helpers work", {
expect_identical(.rstan_sampler_params(stanfit1), list(NA))

stanfit1@stan_args[[1]]$control$max_treedepth <- NULL
expect_equal(.rstan_max_treedepth(stanfit1), 11)
expect_equal(.rstan_max_treedepth(stanfit1), 10)
})


Expand Down Expand Up @@ -127,6 +132,7 @@ test_that("as.shinystan (list of matrices) creates sso", {
expect_s4_class(x, "shinystan")
})
test_that("as.shinystan (stanreg) creates sso", {
skip_if_not_installed("rstanarm")
expect_message(x <- as.shinystan(stanreg1, model_name = "test"),
"preparing graphical posterior predictive checks")
expect_is(x, "shinystan")
Expand All @@ -141,6 +147,7 @@ test_that("as.shinystan (stanreg) creates sso", {
expect_null(x@misc$pp_check_plots)
})
test_that("as.shinystan (stanfit) creates sso", {
skip_if_not_installed("rstanarm")
expect_is(x <- as.shinystan(stanfit1, model_name = "test", note = "test"), "shinystan")
expect_identical(sso_version(x), utils::packageVersion("shinystan"))
})
Expand All @@ -151,6 +158,7 @@ test_that("as.shinystan throws errors", {
})

test_that("as.shinystan arguments works with rstanarm example", {
skip_if_not_installed("rstanarm")
sso1 <- as.shinystan(stanreg1)
sso2 <- as.shinystan(stanreg1, ppd = FALSE)
expect_is(sso1, "shinystan")
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test_that("options set when package loads", {
})

test_that("Can work with CSV files created by RStan", {
skip_if_not_installed("rstanarm")
test_data <- data.frame(Y = rnorm(10))
samples_tmp <- tempfile()
fit <- rstanarm::stan_glm(Y ~ 1, data = test_data, sample_file = samples_tmp, chains = 1, iter = 10, sample_file = samples_tmp)
Expand Down

0 comments on commit f11d054

Please sign in to comment.