Skip to content

Commit

Permalink
Fix vignettes and tests under r-devel
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Jan 19, 2024
1 parent d60aa23 commit dcf3ef2
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 9 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rstantools
Type: Package
Title: Tools for Developing R Packages Interfacing with 'Stan'
Version: 2.4.0
Version: 2.4.0
Date: 2024-01-16
Authors@R:
c(person(given = "Jonah",
Expand Down Expand Up @@ -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)
20 changes: 20 additions & 0 deletions R/rstan_package_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,23 @@
}
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}
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)
}
}
27 changes: 27 additions & 0 deletions man/rstantools-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions man/rstantools_load_code.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tests/testthat/test-rstan_create_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions vignettes/minimal-rstan-package.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

Expand Down

0 comments on commit dcf3ef2

Please sign in to comment.