# Generated by pkglite: do not edit by hand
# Use pkglite::unpack() to restore the packages

Package: example
File: .github/workflows/check.yaml
Format: text
Content:
  # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
  # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
  on: [push, pull_request]
  
  name: check-internal
  
  jobs:
    check-internal:
      runs-on: ${{ matrix.config.os }}
  
      name: ${{ matrix.config.os }} (${{ matrix.config.r }})
  
      strategy:
        fail-fast: false
        matrix:
          config:
            - {os: ubuntu-latest, r: 'release'}
  
      env:
        GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
        NOT_CRAN: true
        R_KEEP_PKG_SOURCE: yes
  
      steps:
        - uses: actions/checkout@v3
  
        - uses: r-lib/actions/setup-pandoc@v2
  
        - uses: r-lib/actions/setup-r@v2
          with:
            r-version: ${{ matrix.config.r }}
            extra-repositories: 'https://mc-stan.org/r-packages/'
            http-user-agent: ${{ matrix.config.http-user-agent }}
            use-public-rspm: true
  
        - name: Install CmdStan
          shell: Rscript {0}
          run: |
            install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
            cmdstanr::check_cmdstan_toolchain(fix = TRUE)
            cmdstanr::install_cmdstan()
  
        - uses: r-lib/actions/setup-r-dependencies@v2
          with:
            extra-packages: any::rcmdcheck, local::.
            needs: check
            cache-version: 2
      
        - uses: r-lib/actions/check-r-package@v2
          with:
            upload-snapshots: true

Package: example
File: .gitignore
Format: text
Content:
  *~
  .Rapp.history
  .RData
  .Rhistory
  .Rproj.user/
  inst/stan/**
  !inst/stan/**/*.*
  inst/stan/**/*.exe
  inst/stan/**/*.EXE
  *.dll

Package: example
File: .Rbuildignore
Format: text
Content:
  ^.*\.Rproj$
  ^\.git$
  ^\.github$
  ^\.gitignore$
  ^\.Rbuildignore$
  ^\.RData$
  ^\.Rhistory$
  ^\.Rproj\.user$
  ^NOTICE$

Package: example
File: DESCRIPTION
Format: text
Content:
  Package: example
  Type: Package
  Title: Example Package With Instantiate
  Version: 0.0.1
  Author: You
  Maintainer: The package maintainer <yourself@somewhere.net>
  Description: Demonstrate how to create an R package with pre-compiled Stan
    models.
  Depends:
    R (>= 4.0.0)
  Imports:
    instantiate
  Additional_repositories:
    https://mc-stan.org/r-packages/
  SystemRequirements: CmdStan (https://mc-stan.org/users/interfaces/cmdstan)
  Encoding: UTF-8
  LazyData: true
  RoxygenNote: 7.2.3

Package: example
File: example.Rproj
Format: text
Content:
  Version: 1.0
  
  RestoreWorkspace: Default
  SaveWorkspace: Default
  AlwaysSaveHistory: Default
  
  EnableCodeIndexing: Yes
  UseSpacesForTab: Yes
  NumSpacesForTab: 2
  Encoding: UTF-8
  
  RnwWeave: Sweave
  LaTeX: pdfLaTeX
  
  BuildType: Package
  PackageUseDevtools: Yes
  PackageInstallArgs: --no-multiarch --with-keep.source

Package: example
File: inst/stan/bernoulli.stan
Format: text
Content:
  /*
  * This model was borrowed from the CmdStan projec with the BSD 3-Clause License.
  
  BSD 3-Clause License
  =====================
  
  Copyright (c) 2019, Stan Developers and their Assignees
  All rights reserved.
  
  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:
  
  1. Redistributions of source code must retain the above copyright notice, this
     list of conditions and the following disclaimer.
  
  2. Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation
     and/or other materials provided with the distribution.
  
  3. Neither the name of the copyright holder nor the names of its
     contributors may be used to endorse or promote products derived from
     this software without specific prior written permission.
  
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  
  data {
    int<lower=0> N;
    array[N] int<lower=0,upper=1> y;
  }
  parameters {
    real<lower=0,upper=1> theta;
  }
  model {
    theta ~ beta(1,1);  // uniform prior on interval 0,1
    y ~ bernoulli(theta);
  }

Package: example
File: man/example-package.Rd
Format: text
Content:
  % Generated by roxygen2: do not edit by hand
  % Please edit documentation in R/package.R
  \docType{package}
  \name{example-package}
  \alias{example-package}
  \title{example: Example Package With Instantiate}
  \concept{help}

Package: example
File: man/run_bernoulli_model.Rd
Format: text
Content:
  % Generated by roxygen2: do not edit by hand
  % Please edit documentation in R/model.R
  \name{run_bernoulli_model}
  \alias{run_bernoulli_model}
  \title{Fit the Bernoulli model.}
  \usage{
  run_bernoulli_model(y, ...)
  }
  \arguments{
  \item{y}{Numeric vector of Bernoulli observations (zeroes and ones).}
  
  \item{`...`}{Named arguments to the `sample()` method of CmdStan model
  objects: <https://mc-stan.org/cmdstanr/reference/model-method-sample.html>}
  }
  \value{
  A data frame of posterior summaries.
  }
  \description{
  Fit the Bernoulli Stan model and return posterior summaries.
  }
  \examples{
  if (instantiate::stan_cmdstan_exists()) {
    run_bernoulli_model(y = c(1, 0, 1, 0, 1, 0, 0, 0, 0, 0))
  }
  }
  \concept{models}

Package: example
File: NAMESPACE
Format: text
Content:
  # Generated by roxygen2: do not edit by hand
  
  export(run_bernoulli_model)
  importFrom(instantiate,stan_package_model)

Package: example
File: NOTICE
Format: text
Content:
  This package includes components from other open-source software. The projects and licenses are listed below.
  
  * CmdStan (https://github.com/stan-dev/cmdstan) by Stan Developers and their Assignees.
  
  BSD 3-Clause License
  =====================
  
  Copyright (c) 2014, Stan
  All rights reserved.
  
  Redistribution and use in source and binary forms, with or without modification,
  are permitted provided that the following conditions are met:
  
  * Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.
  
  * Redistributions in binary form must reproduce the above copyright notice, this
    list of conditions and the following disclaimer in the documentation and/or
    other materials provided with the distribution.
  
  * Neither the name of the {organization} nor the names of its
    contributors may be used to endorse or promote products derived from
    this software without specific prior written permission.
  
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Package: example
File: R/model.R
Format: text
Content:
  #' @title Fit the Bernoulli model.
  #' @export
  #' @family models
  #' @description Fit the Bernoulli Stan model and return posterior summaries.
  #' @return A data frame of posterior summaries.
  #' @param y Numeric vector of Bernoulli observations (zeroes and ones).
  #' @param `...` Named arguments to the `sample()` method of CmdStan model
  #'   objects: <https://mc-stan.org/cmdstanr/reference/model-method-sample.html>
  #' @examples
  #' if (instantiate::stan_cmdstan_exists()) {
  #'   run_bernoulli_model(y = c(1, 0, 1, 0, 1, 0, 0, 0, 0, 0))
  #' }
  run_bernoulli_model <- function(y, ...) {
    stopifnot(is.numeric(y) && all(y >= 0 & y <= 1))
    model <- instantiate::stan_package_model(
      name = "bernoulli",
      package = "example"
    )
    fit <- model$sample(data = list(N = length(y), y = y), ...)
    fit$summary()
  }

Package: example
File: R/package.R
Format: text
Content:
  #' example: Example Package With Instantiate
  #' @docType package
  #' @name example-package
  #' @family help
  #' @importFrom instantiate stan_package_model
  NULL

