1111# this program; if not, see <http://www.gnu.org/licenses/>.
1212
1313
14- # ' Launch the ShinyStan app
14+ # ' Launch the ' ShinyStan' app
1515# '
16- # ' Launch the ShinyStan app in the default web browser. RStudio users also have
17- # ' the option of launching the app in RStudio's pop-up Viewer.
16+ # ' Launch the ' ShinyStan' app in the default web browser. ' RStudio' users also
17+ # ' have the option of launching the app in the pop-up Viewer.
1818# '
1919# ' @export
20- # ' @param object An object of class shinystan, stanfit, or stanreg. To use other
21- # ' types of objects first create a shinystan object using
20+ # ' @param object The object to use. For the default method this can be an object
21+ # ' of class \code{"shinystan"}, \code{"stanfit"}, or \code{"stanreg"}. To use
22+ # ' other types of objects first create a shinystan object using
2223# ' \code{\link{as.shinystan}}.
23- # ' @param rstudio Only relevant for RStudio users. The default (\code{FALSE}) is
24- # ' to launch the app in the user's default web browser rather than RStudio's
25- # ' pop-up Viewer. Users can change the default to \code{TRUE} by setting the
26- # ' global option \code{options(shinystan.rstudio = TRUE)}.
24+ # ' @param rstudio Only relevant for 'RStudio' users. The default (\code{FALSE})
25+ # ' is to launch the app in the user's default web browser rather than the
26+ # ' pop-up Viewer provided by 'RStudio'. Users can change the default to
27+ # ' \code{TRUE} by setting the global option \code{options(shinystan.rstudio =
28+ # ' TRUE)}.
2729# ' @param ... Optional arguments passed to \code{\link[shiny]{runApp}}.
2830# '
2931# ' @return The \code{launch_shinystan} function is used for the side effect of
30- # ' starting the ShinyStan app, but it also returns a shinystan object, an
31- # ' instance of S4 class \code{"shinystan"}.
32+ # ' starting the ' ShinyStan' app, but it also returns a \code{ shinystan}
33+ # ' object, an instance of S4 class \code{"shinystan"}.
3234# '
3335# ' @template seealso-as.shinystan
3436# ' @template seealso-update_sso
6971# ' # Example 3: 'fit' is an mcmc.list, array or list of matrices
7072# ' #######################################
7173# '
72- # ' # First create shinystan object (see ?as.shinystan for full details)
73- # ' fit_sso <- as.shinystan(fit, model_name = "Example")
74- # '
75- # ' # Now fit_sso is a shinystan object and so Example 1 (above) applies.
74+ # ' # First create shinystan object (see ?as.shinystan) for full details)
7675# ' }
7776# '
78- launch_shinystan <- function (object ,
79- rstudio = getOption(" shinystan.rstudio" ),
80- ... ) {
81- if (is.shinystan(object )) {
82- sso_check(object )
83- } else if (is.stanreg(object ) || is.stanfit(object )) {
84- message(" \n Creating shinystan object..." )
77+ launch_shinystan <- function (object , ... ) {
78+ UseMethod(" launch_shinystan" )
79+ }
80+
81+ # ' @rdname launch_shinystan
82+ # ' @export
83+ launch_shinystan.default <-
84+ function (object ,
85+ ... ,
86+ rstudio = getOption(" shinystan.rstudio" )) {
87+ if (! is.shinystan(object ) &&
88+ ! is.stanfit(object ) &&
89+ ! is.stanreg(object )) {
90+ stop(" object not compatible with 'launch_shinystan'. " ,
91+ " Try converting to a shinystan object first using 'as.shinystan'." )
92+ }
8593 object <- as.shinystan(object )
94+ message(" \n Launching ShinyStan interface... " ,
95+ " for large models this may take some time." )
96+ invisible (launch(object , rstudio , ... ))
97+ }
98+
99+ # ' @rdname launch_shinystan
100+ # ' @export
101+ launch_shinystan.shinystan <-
102+ function (object ,
103+ ... ,
104+ rstudio = getOption(" shinystan.rstudio" )) {
105+ sso_check(object )
106+ message(" \n Launching ShinyStan interface... " ,
107+ " for large models this may take some time." )
108+ invisible (launch(object , rstudio , ... ))
86109 }
87- if (! is.shinystan(object ))
88- stop(" 'object' is not a valid input. See help('launch_shinystan')." )
89-
90- message(" \n Launching ShinyStan interface... " ,
91- " for large models this may take some time." )
92- invisible (launch(object , rstudio , ... ))
93- }
94110
95111
96- # ' ShinyStan demo
112+ # ' ' ShinyStan' demo
97113# '
98114# ' @aliases eight_schools
99115# ' @export
@@ -102,8 +118,8 @@ launch_shinystan <- function(object,
102118# ' the only option, but additional demos may be available in future releases.
103119# ' \describe{
104120# ' \item{\code{eight_schools}}{Hierarchical meta-analysis model. See
105- # ' \emph{Meta Analysis} chapter of the Stan manual (chapter 11.2 in version
106- # ' 2.9), \url{http://mc-stan.org/documentation/}.}
121+ # ' \emph{Meta Analysis} chapter of the ' Stan' manual
122+ # ' \url{http://mc-stan.org/users /documentation/}.}
107123# ' }
108124# ' @return An S4 shinystan object.
109125# '
0 commit comments