diff --git a/.github/workflows/check-standalone.yaml b/.github/workflows/check-standalone.yaml index ceeb27a..60afb95 100644 --- a/.github/workflows/check-standalone.yaml +++ b/.github/workflows/check-standalone.yaml @@ -42,8 +42,7 @@ jobs: - name: Checkout lgpr package run: | - git clone https://github.com/andrjohns/lgpr - cd lgpr && git checkout array-syntax + git clone https://github.com/jtimonen/lgpr - name: Check against CRAN StanHeaders and CRAN RStan run: | diff --git a/DESCRIPTION b/DESCRIPTION index ff7a200..84163f9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: rstantools Type: Package Title: Tools for Developing R Packages Interfacing with 'Stan' -Version: 2.3.1.1 -Date: 2023-07-18 +Version: 2.4.0 +Date: 2024-01-22 Authors@R: c(person(given = "Jonah", family = "Gabry", @@ -53,6 +53,6 @@ Suggests: roxygen2 (>= 6.0.1), rmarkdown, rstudioapi -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 VignetteBuilder: knitr Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 8b761fe..5603627 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,6 +24,7 @@ export(predictive_interval) export(prior_summary) export(rstan_config) export(rstan_create_package) +export(rstantools_load_code) export(use_rstan) importFrom(RcppParallel,RcppParallelLibs) importFrom(stats,quantile) diff --git a/NEWS.md b/NEWS.md index d7fd66a..2c75470 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# rstantools 2.4.0 + +* Update to match CRAN's patched version by @jgabry in #114 +* Include additional template imports to suppress NOTEs by @andrjohns in #115 +* Fix packages with stanfunctions under rstan 2.33+ by @andrjohns in #117 + + # rstantools 2.3.1 * Deprecated `init_cpp`. (#105) diff --git a/R/rstan_create_package.R b/R/rstan_create_package.R index 81f3991..f3a9236 100644 --- a/R/rstan_create_package.R +++ b/R/rstan_create_package.R @@ -46,7 +46,7 @@ #' @param stan_files A character vector with paths to `.stan` files to include #' in the package. #' @param roxygen Should \pkg{roxygen2} be used for documentation? Defaults to -#' `TRUE`. If so, a file `R/{pkgname}-package.R`` is added to the package with +#' `TRUE`. If so, a file `R/{pkgname}-package.R` is added to the package with #' roxygen tags for the required import lines. See the **Note** section below #' for advice specific to the latest versions of \pkg{roxygen2}. #' @param travis Should a `.travis.yml` file be added to the package directory? diff --git a/R/rstan_package_utils.R b/R/rstan_package_utils.R index 3200e4f..050e38d 100644 --- a/R/rstan_package_utils.R +++ b/R/rstan_package_utils.R @@ -103,3 +103,24 @@ } invisible(acc) } + +#' Helper function for loading code in roxygenise +#' +#' Adapted from the \code{sourceDir} function defined +#' by \code{example(source)}. +#' +#' @param path Path to directory containing code to load +#' @param trace Whether to print file names as they are loaded +#' @param ... Additional arguments passed to \code{\link{source}} +#' +#' @return \code{NULL} +#' @export +rstantools_load_code <- function(path, trace = TRUE, ...) { + op <- options(); on.exit(options(op)) # to reset after each + for (nm in list.files(path, pattern = "[.][RrSsQq]$")) { + if (trace) cat(nm, ":") + source(file.path(path, nm), ...) + if (trace) cat("\n") + options(op) + } +} diff --git a/man/rstan_create_package.Rd b/man/rstan_create_package.Rd index 0a6d7b0..c4184ad 100644 --- a/man/rstan_create_package.Rd +++ b/man/rstan_create_package.Rd @@ -30,7 +30,7 @@ project.} in the package.} \item{roxygen}{Should \pkg{roxygen2} be used for documentation? Defaults to -\code{TRUE}. If so, a file `R/{pkgname}-package.R`` is added to the package with +\code{TRUE}. If so, a file \code{R/{pkgname}-package.R} is added to the package with roxygen tags for the required import lines. See the \strong{Note} section below for advice specific to the latest versions of \pkg{roxygen2}.} diff --git a/man/rstantools-package.Rd b/man/rstantools-package.Rd index b1532b0..7b6a5b2 100644 --- a/man/rstantools-package.Rd +++ b/man/rstantools-package.Rd @@ -30,4 +30,31 @@ can be found in the vignettes included with \pkg{rstantools} and at your package let us know on the the \href{https://discourse.mc-stan.org}{Stan Forums} or at the \pkg{rstantools} GitHub \href{https://github.com/stan-dev/rstantools/issues}{issue tracker}. } + +Useful links: +\itemize{ + \item \url{https://mc-stan.org/rstantools/} + \item \url{https://discourse.mc-stan.org/} + \item Report bugs at \url{https://github.com/stan-dev/rstantools/issues} +} + +} +\author{ +\strong{Maintainer}: Jonah Gabry \email{jsg2201@columbia.edu} + +Authors: +\itemize{ + \item Ben Goodrich \email{benjamin.goodrich@columbia.edu} + \item Martin Lysy \email{mlysy@uwaterloo.ca} + \item Andrew Johnson +} + +Other contributors: +\itemize{ + \item Hamada S. Badr [contributor] + \item Marco Colombo [contributor] + \item Stefan Siegert [contributor] + \item Trustees of Columbia University [copyright holder] +} + } diff --git a/man/rstantools_load_code.Rd b/man/rstantools_load_code.Rd new file mode 100644 index 0000000..97d1dba --- /dev/null +++ b/man/rstantools_load_code.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/rstan_package_utils.R +\name{rstantools_load_code} +\alias{rstantools_load_code} +\title{Helper function for loading code in roxygenise} +\usage{ +rstantools_load_code(path, trace = TRUE, ...) +} +\arguments{ +\item{path}{Path to directory containing code to load} + +\item{trace}{Whether to print file names as they are loaded} + +\item{...}{Additional arguments passed to \code{\link{source}}} +} +\value{ +\code{NULL} +} +\description{ +Adapted from the \code{sourceDir} function defined +by \code{example(source)}. +} diff --git a/man/use_rstan.Rd b/man/use_rstan.Rd index 7b9029c..649954d 100644 --- a/man/use_rstan.Rd +++ b/man/use_rstan.Rd @@ -41,7 +41,7 @@ Stan C++ classes to \R. Stan C++ code. \item If \code{NAMESPACE} file is generic (i.e., created by \code{\link[=rstan_create_package]{rstan_create_package()}}), append \code{import(Rcpp, methods)}, \code{importFrom(rstan, sampling)}, -\code{importFrom(rstantools, rstan_config)}, \code{importFrom(RcppParallel, RcppParallelLibs)} +\code{importFrom(rstantools, rstan_config)}, \code{importFrom(RcppParallel, RcppParallelLibs)}, and \code{useDynLib} directives. If \code{NAMESPACE} is not generic, display message telling user what to add to \code{NAMESPACE} for themselves. } diff --git a/tests/testthat/test-rstan_create_package.R b/tests/testthat/test-rstan_create_package.R index e596e12..1bae1d7 100644 --- a/tests/testthat/test-rstan_create_package.R +++ b/tests/testthat/test-rstan_create_package.R @@ -94,8 +94,7 @@ for(ii in 1:ntest) { skip_on_cran() skip_on_travis() } - example(source) # defines the sourceDir() function - try(roxygen2::roxygenize(pkg_dest_path, load_code = sourceDir), silent = TRUE) + try(roxygen2::roxygenize(pkg_dest_path, load_code = rstantools_load_code), silent = TRUE) pkgbuild::compile_dll(pkg_dest_path) tmp <- capture.output(load_out <- pkgload::load_all(pkg_dest_path, export_all = TRUE, diff --git a/vignettes/minimal-rstan-package.Rmd b/vignettes/minimal-rstan-package.Rmd index c13af8d..050b451 100644 --- a/vignettes/minimal-rstan-package.Rmd +++ b/vignettes/minimal-rstan-package.Rmd @@ -238,15 +238,12 @@ for `lm_stan` and update the `NAMESPACE` so the function is exported, i.e., available to users when the package is installed. This can be done with the function `roxygen2::roxygenize()`, which needs to be called twice initially. -```{r, results = "hide"} -example(source) # defines the sourceDir() function -``` ```{r, eval = FALSE} -try(roxygen2::roxygenize(load_code = sourceDir), silent = TRUE) +try(roxygen2::roxygenize(load_code = rstantools_load_code), silent = TRUE) roxygen2::roxygenize() ``` ```{r, echo=FALSE, results="hide"} -try(roxygen2::roxygenize(PATH, load_code = sourceDir), silent = TRUE) +try(roxygen2::roxygenize(PATH, load_code = rstantools_load_code), silent = TRUE) roxygen2::roxygenize(PATH) ```