From ae436073625154140a6f79cd8efd78fbdf505fda Mon Sep 17 00:00:00 2001 From: Michael DeWitt Date: Wed, 23 Jul 2025 07:37:23 -0400 Subject: [PATCH 1/6] vscode stuff --- .Rbuildignore | 5 ++++- .gitignore | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.Rbuildignore b/.Rbuildignore index 3d888e1..307f466 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -14,4 +14,7 @@ ^\.pre-commit-config\.yaml$ ^doc$ ^Meta$ -^README\.html$ \ No newline at end of file +^README\.html$ +^cran-comments\.md$ +^CRAN-SUBMISSION$ +^.vscode$ diff --git a/.gitignore b/.gitignore index e77a603..8c7370c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ inst/doc /doc/ /Meta/ +.vscode/ \ No newline at end of file From 32c5266c8ce7ed312849dec86528857a980fab53 Mon Sep 17 00:00:00 2001 From: Michael DeWitt Date: Wed, 23 Jul 2025 07:37:36 -0400 Subject: [PATCH 2/6] Tweak description per stan requirements --- DESCRIPTION | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6a7bca1..2d2fa56 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: staninside -Title: Facilitating the Use of Stan Within Packages +Title: "Facilitating the Use of 'Stan' Within Packages" Version: 0.0.4 Authors@R: person(given = "Michael", @@ -8,13 +8,12 @@ Authors@R: email = "me.dewitt.jr@gmail.com", comment = c(ORCID = "0000-0001-8940-1967")) Description: Infrastructure and functions that can be used for - integrating Stan code into stand alone R packages which in turn use the - CmdStan engine (often accessed through CmdStanR). Using CmdStanR and - pre-written Stan code can make package installation easy and less prone to - fail because it removes the need for Rcpp and RStan packages(and their dependencies). - Using CmdStanR will also afford users the opportunity to use the latest developments - within CmdStan. However, building these packages requires some work and this - package provides tools to assist with that process. + integrating 'Stan' (Carpenter et al., 2017 ) code into + stand alone R packages which in turn use the 'CmdStan' engine (often accessed through + 'CmdStanR' (Stan Development Team, 2025 )). + Using 'CmdStanR' and pre-written 'Stan' code can make package installation easy. Using 'staninside' + offers a way to cache user-compiled 'Stan' models in user-specified directories reducing the need + to recompile the same model multiple times. License: MIT + file LICENSE URL: https://github.com/medewitt/staninside, https://medewitt.github.io/staninside/ BugReports: https://github.com/medewitt/staninside/issues From 1328d17a346f3452f0924d22e4ec5fdee2ea2f1f Mon Sep 17 00:00:00 2001 From: Michael DeWitt Date: Wed, 23 Jul 2025 07:39:58 -0400 Subject: [PATCH 3/6] remove find.packages --- R/find_stan_code.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/R/find_stan_code.R b/R/find_stan_code.R index fb271f6..9acc04e 100644 --- a/R/find_stan_code.R +++ b/R/find_stan_code.R @@ -12,9 +12,7 @@ #' @examples #' find_stan_code(pkgname = "staninside") find_stan_code <- function(pkgname = "staninside") { - if (!pkgname %in% rownames(installed.packages())) { - stop(sprintf("`%s` is not an installed package.\n", pkgname)) - } + requireNamespace(pkgname) stan_pkg_location <- fs::dir_ls(system.file(package = pkgname), glob = "*.stan", recurse = TRUE From 1b24789cecdbf46530b4127087d8fe9f91d2aa70 Mon Sep 17 00:00:00 2001 From: Michael DeWitt Date: Wed, 23 Jul 2025 08:17:32 -0400 Subject: [PATCH 4/6] updating package --- R/copy_models.R | 11 ++++++++++- R/setup_stan_package.R | 15 +++++++-------- man/copy_models.Rd | 3 ++- man/setup_stan_package.Rd | 3 +-- man/staninside-package.Rd | 4 ++-- tests/testthat/test-clear_stan_cache.R | 22 ++++++++-------------- tests/testthat/test-copy_models.R | 8 +++++--- tests/testthat/test-setup_stan_package.R | 8 ++++++-- vignettes/using-staninside.Rmd | 5 +++-- 9 files changed, 44 insertions(+), 35 deletions(-) diff --git a/R/copy_models.R b/R/copy_models.R index 5f3927c..849a10b 100644 --- a/R/copy_models.R +++ b/R/copy_models.R @@ -5,7 +5,8 @@ #' #' @param pkgname a string, the name of the package #' @param local_location a file path representing the desired location -#' of the local copy. +#' of the local copy. If "default" is provided, the function will use +#' the user cache directory for the package. #' @returns file path of newly created files #' @importFrom fs dir_create dir_exists file_copy #' @export @@ -15,8 +16,16 @@ #' copy_models(pkgname = "staninside", local_location = local_location) copy_models <- function(pkgname = "staninside", local_location = NULL) { if (is.null(local_location)) { + stop("A location must be provided") + } + + if (local_location == "default") { local_location <- rappdirs::user_cache_dir(appname = pkgname) cli::cli_alert("`{local_location}` will be used") + } else { + if (!dir.exists(local_location)) { + stop("The directory you have indicated does not exist") + } } stan_code_to_copy <- find_stan_code(pkgname) diff --git a/R/setup_stan_package.R b/R/setup_stan_package.R index 287805b..450d544 100644 --- a/R/setup_stan_package.R +++ b/R/setup_stan_package.R @@ -3,8 +3,7 @@ #' Create directory and helper files for a Stan package using #' CmdStanR #' -#' @param loc a file.path indicating package root with a default of the -#' current working directory +#' @param loc a file.path indicating package root. #' @param use_all a logical indicating if each section of Stan code #' should have it's own directory with a default of \code{TRUE} #' @returns invisible null @@ -22,12 +21,12 @@ #' @export setup_stan_package <- function(loc = NULL, use_all = TRUE) { - if (!is.null(loc)) { - if (!dir.exists(loc)) { - stop("The directory you have indicated does not exist,") - } - } else { - loc <- getwd() + if (is.null(loc)) { + stop("A location must be provided") + } + + if (!dir.exists(loc)) { + stop("The directory you have indicated does not exist,") } target_path <- file.path(loc, "inst", "stan") diff --git a/man/copy_models.Rd b/man/copy_models.Rd index ab0b81b..4b4f04c 100644 --- a/man/copy_models.Rd +++ b/man/copy_models.Rd @@ -10,7 +10,8 @@ copy_models(pkgname = "staninside", local_location = NULL) \item{pkgname}{a string, the name of the package} \item{local_location}{a file path representing the desired location -of the local copy.} +of the local copy. If "default" is provided, the function will use +the user cache directory for the package.} } \value{ file path of newly created files diff --git a/man/setup_stan_package.Rd b/man/setup_stan_package.Rd index 8b26d8a..3b48f75 100644 --- a/man/setup_stan_package.Rd +++ b/man/setup_stan_package.Rd @@ -7,8 +7,7 @@ setup_stan_package(loc = NULL, use_all = TRUE) } \arguments{ -\item{loc}{a file.path indicating package root with a default of the -current working directory} +\item{loc}{a file.path indicating package root.} \item{use_all}{a logical indicating if each section of Stan code should have it's own directory with a default of \code{TRUE}} diff --git a/man/staninside-package.Rd b/man/staninside-package.Rd index c55f90d..87bef43 100644 --- a/man/staninside-package.Rd +++ b/man/staninside-package.Rd @@ -4,9 +4,9 @@ \name{staninside-package} \alias{staninside} \alias{staninside-package} -\title{staninside: Facilitating the Use of Stan Within Packages} +\title{staninside: "Facilitating the Use of 'Stan' Within Packages"} \description{ -Infrastructure and functions that can be used for integrating Stan code into stand alone R packages which in turn use the CmdStan engine (often accessed through CmdStanR). Using CmdStanR and pre-written Stan code can make package installation easy and less prone to fail because it removes the need for Rcpp and RStan packages(and their dependencies). Using CmdStanR will also afford users the opportunity to use the latest developments within CmdStan. However, building these packages requires some work and this package provides tools to assist with that process. +Infrastructure and functions that can be used for integrating 'Stan' (Carpenter et al., 2017 \doi{10.18637/jss.v076.i01}) code into stand alone R packages which in turn use the 'CmdStan' engine (often accessed through 'CmdStanR' (Stan Development Team, 2025 \url{https://mc-stan.org/users/interfaces/cmdstanr/})). Using 'CmdStanR' and pre-written 'Stan' code can make package installation easy. Using 'staninside' offers a way to cache user-compiled 'Stan' models in user-specified directories reducing the need to recompile the same model multiple times. } \seealso{ Useful links: diff --git a/tests/testthat/test-clear_stan_cache.R b/tests/testthat/test-clear_stan_cache.R index c9df95e..476bebb 100644 --- a/tests/testthat/test-clear_stan_cache.R +++ b/tests/testthat/test-clear_stan_cache.R @@ -1,21 +1,15 @@ +test_clearing_cache <- function() { + # Copy over models + app_loc <- tempdir() + loc <- copy_models(pkgname = "staninside", local_location = app_loc) + copied_over_files <- all(c("test.stan", "func.stan") %in% basename(loc)) + clear_stan_cache(pkgname = "staninside") -test_clearing_cache <- function(){ - - # Copy over models - app_loc <- rappdirs::user_cache_dir("staninside") - loc <- copy_models(pkgname = "staninside", local_location = app_loc) - - copied_over_files <- all(c("test.stan", "func.stan") %in% basename(loc)) - - clear_stan_cache(pkgname = "staninside") - - all_removed <- !isTRUE(lapply(loc, file.exists)) - - all(copied_over_files,all_removed) - + all_removed <- !isTRUE(lapply(loc, file.exists)) + all(copied_over_files, all_removed) } test_that("stan files can be copied over and cleared", { diff --git a/tests/testthat/test-copy_models.R b/tests/testthat/test-copy_models.R index d559842..b622d9a 100644 --- a/tests/testthat/test-copy_models.R +++ b/tests/testthat/test-copy_models.R @@ -1,7 +1,7 @@ # Make model available local_location <- tempdir() -copy_models(pkgname = "staninside", local_location = local_location) +copy_models(pkgname = "staninside", local_location = local_location) test_stan <- list.files(local_location, full.names = TRUE, pattern = "test.stan") @@ -10,7 +10,9 @@ test_that("models from test package have been copied", { }) test_that("test that all stan directories are available", { - expect_true(dir.exists(file.path(local_location, "functions"))) + expect_true(dir.exists(file.path(local_location, "functions"))) }) - +test_that("test that when no location is provided, an error is thrown", { + expect_error(copy_models(pkgname = "staninside")) +}) diff --git a/tests/testthat/test-setup_stan_package.R b/tests/testthat/test-setup_stan_package.R index 4c7a5aa..34de02c 100644 --- a/tests/testthat/test-setup_stan_package.R +++ b/tests/testthat/test-setup_stan_package.R @@ -6,9 +6,13 @@ test_that("full process functional", { expect_true(dir.exists(file.path(test_dir, "inst", "stan"))) }) test_that("sub directories created functional", { - expect_true(dir.exists(file.path(test_dir, "inst", "stan", "data"))) + expect_true(dir.exists(file.path(test_dir, "inst", "stan", "data"))) }) test_that("fails on invalid path", { - expect_error(setup_stan_package("blerg")) + expect_error(setup_stan_package("blerg")) +}) + +test_that("fails on no location", { + expect_error(setup_stan_package()) }) diff --git a/vignettes/using-staninside.Rmd b/vignettes/using-staninside.Rmd index cefe5ed..364392c 100644 --- a/vignettes/using-staninside.Rmd +++ b/vignettes/using-staninside.Rmd @@ -37,7 +37,8 @@ If a package developer were to build a package with `staninside`, they first cou Next, to build the appropriate structure the author could call ```r -setup_stan_package() +temp_dir <- tempdir() +setup_stan_package(loc = temp_dir) ``` This function will create the following directory tree: @@ -77,7 +78,7 @@ fit_my_data <- function(my_data){ "Use `staninside::clear_stan_cache('mypackage')` if you need to refresh") } else { cli::cli_alert_info("Copying Stan models to cache") - staninside::copy_models(this_pkg()) + staninside::copy_models(pkgname = "mypackage", local_location = local_location) cli::cli_alert_success("Models copied!") } From d8a16043d7b790ede03f4d905b812e7586be3159 Mon Sep 17 00:00:00 2001 From: Michael DeWitt Date: Wed, 23 Jul 2025 10:02:38 -0400 Subject: [PATCH 5/6] updating CRAN comments --- inst/WORDLIST | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/inst/WORDLIST b/inst/WORDLIST index 593363e..78536f3 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,41 +1,45 @@ -aut -BugReports -cli CMD CmdStan CmdStanR Codecov +Github +ORCID +RStan +Rcpp +TMPDIR +al +cmdstanr +doi +et +filespace +jss +pre +testthat +tinytest +BugReports +CRAN Config +DeWitt +LazyData +Roxygen +RoxygenNote +VignetteBuilder +aut +cli covr cran -CRAN cre dewitt -DeWitt dplyr -filespace fs github -Github gmail https knitr -LazyData medewitt michaeldewittjr -ORCID -pre rappdirs -Rcpp rmarkdown -Roxygen -RoxygenNote rstan -RStan staninside -testthat -tidyverse -tinytest -TMPDIR -VignetteBuilder -cmdstanr \ No newline at end of file +tidyverse \ No newline at end of file From 174d2fca51d3b8712728267d3e4b6c280b537578 Mon Sep 17 00:00:00 2001 From: Michael DeWitt Date: Wed, 23 Jul 2025 10:05:16 -0400 Subject: [PATCH 6/6] Ignore proper things --- .gitignore | 3 ++- cran-comments.md | 14 ++++++++++++++ vignettes/.gitignore | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 cran-comments.md diff --git a/.gitignore b/.gitignore index 8c7370c..a49f39b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ inst/doc /doc/ /Meta/ -.vscode/ \ No newline at end of file +.vscode/ +CRAN-SUBMISSION \ No newline at end of file diff --git a/cran-comments.md b/cran-comments.md new file mode 100644 index 0000000..78caa17 --- /dev/null +++ b/cran-comments.md @@ -0,0 +1,14 @@ +## R CMD check results + +0 errors | 0 warnings | 0 notes + +* This is a new package and a resubmission +* This package has been tested on local MAC and rub using the Rhub Github Actions tools to test Linux, Mac, Windows. + +### Issue resolved from submission +- Properly cited methods in the DESCRIPTION +- Update packages, software, and APIs with single quotations +- Removed all `getwd` statements as defaults and require user to explicity enter file path +- Vignettes do not utilize any local, package, or user directories +- Title has double quotes +- Removed use of `installed.packages()` to use `requireNamespace` \ No newline at end of file diff --git a/vignettes/.gitignore b/vignettes/.gitignore index 097b241..13bc4a7 100644 --- a/vignettes/.gitignore +++ b/vignettes/.gitignore @@ -1,2 +1,4 @@ *.html *.R +CRAN-SUBMISSION +CRAN* \ No newline at end of file