Skip to content

Commit 68ef7c1

Browse files
committed
clean up documents and documentation
1 parent d853304 commit 68ef7c1

8 files changed

Lines changed: 34 additions & 9 deletions

File tree

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
^_push\.R$
1313
^Makefile$
1414
^\.pre-commit-config\.yaml$
15+
^doc$
16+
^Meta$

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
.httr-oauth
55
.DS_Store
66
inst/doc
7+
/doc/
8+
/Meta/

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ export(clear_stan_cache)
55
export(copy_models)
66
export(find_stan_code)
77
export(setup_stan_package)
8+
importFrom(fs,dir_create)
9+
importFrom(fs,dir_exists)
10+
importFrom(fs,file_copy)
11+
importFrom(rappdirs,user_cache_dir)
812
importFrom(utils,installed.packages)

R/clear_stan_cache.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
#' @section Warning:
88
#' This will removed cached models and requires that `rappdirs` is installed
99
#' @returns invisible null
10+
#' @importFrom rappdirs user_cache_dir
1011
#' @export
1112

12-
clear_stan_cache <- function(pkgname){
13-
requireNamespace(pkgname)
14-
app_loc <- rappdirs::user_cache_dir(pkgname)
15-
unlink(app_loc, recursive = TRUE)
16-
invisible(NULL)
13+
clear_stan_cache <- function(pkgname) {
14+
requireNamespace(pkgname)
15+
app_loc <- rappdirs::user_cache_dir(pkgname)
16+
unlink(app_loc, recursive = TRUE)
17+
invisible(NULL)
1718
}

R/copy_models.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#' @param local_location a file path representing the desired location
88
#' of the local copy.
99
#' @returns file path of newly created files
10+
#' @importFrom fs dir_create dir_exists file_copy
1011
#' @export
1112
#'
1213
#' @examples

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
coverage](https://codecov.io/gh/medewitt/staninside/branch/main/graph/badge.svg)](https://codecov.io/gh/medewitt/staninside?branch=main)
1111
[![CRAN
1212
status](https://www.r-pkg.org/badges/version/staninside)](https://CRAN.R-project.org/package=staninside)
13+
[![R-CMD-check](https://github.com/medewitt/staninside/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/medewitt/staninside/actions/workflows/R-CMD-check.yaml)
1314
<!-- badges: end -->
1415

1516
The goal of staninside is to facilitate the use of

_push.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
devtools::document()
2+
devtools::build_readme()
3+
devtools::build_vignettes()
4+
devtools::check()
5+
16
rmarkdown::render("README.Rmd", output_file = "README.md")
27
pkgdown::build_site()
38
codemetar::write_codemeta()

vignettes/using-staninside.Rmd

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ These separate `.stan` files can then be accessed within the Stan code with the
6363

6464
Generally speaking, there will be some function in an R package that will fit the data to a model.
6565
In order to facilitate this fitting with a CmdStanR backend, a process like that below could be used.
66+
Note that this model assumes that cmdstanr is installed, though this could be replaced with other ways of calling Stan (e.g., `rstan`).
6667

6768
```r
6869

@@ -73,22 +74,30 @@ fit_my_data <- function(my_data){
7374
if (length(list.files(local_location, pattern = ".stan")) > 1) {
7475
cli::cli_alert_info("Using cached Stan models")
7576
cli::cli_alert_info(
76-
"Use `intervalcalc::clear_cache` if you need to refresh")
77+
"Use `staninside::clear_stan_cache('mypackage')` if you need to refresh")
7778
} else {
7879
cli::cli_alert_info("Copying Stan models to cache")
7980
staninside::copy_models(this_pkg())
8081
cli::cli_alert_success("Models copied!")
8182
}
8283

8384
model_file_path <- file.path(local_location, paste0("base", ".stan"))
84-
mod <- cmdstanr::cmdstan_model(model_file_path)
85+
mod <- cmdstanr::cmdstan_model(model_file_path)
8586

86-
fit <- mod$sample(data = my_data)
87+
fit <- mod$sample(data = my_data)
8788

88-
return(fit)
89+
return(fit)
8990
}
9091

9192
```
9293

94+
You now can call `fit_my_data` to fit your model.
95+
The underlying Stan code is stored in the user cache directory and will be compiled on the first model fitting operation.
96+
97+
98+
99+
100+
101+
93102

94103

0 commit comments

Comments
 (0)