Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/R-CMD-check-cran.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
# Check CmdStanR the way CRAN does: NOT_CRAN unset and no CmdStan
# installed, so only the tests that need neither run.
# yamllint disable rule:line-length

name: CRAN check

'on':
push:
branches:
- master
pull_request:
branches:
- master
- v1.0

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
R-CMD-check-cran:
if: "! contains(github.event.head_commit.message, '[ci skip]')"
runs-on: ubuntu-latest

name: ubuntu-latest (release, CRAN)

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
PKG_SYSREQS_DB_UPDATE_TIMEOUT: 30s

steps:
- uses: actions/checkout@v7

- uses: r-lib/actions/setup-r@v2
with:
r-version: 'release'

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r-dependencies@v2
with:
cache: "always"
extra-packages: any::rcmdcheck, local::.

# setup-r exports NOT_CRAN=true, which would evaluate the vignettes and
# run every test; CRAN leaves it unset.
- uses: r-lib/actions/check-r-package@v2
env:
NOT_CRAN: false
_R_CHECK_CRAN_INCOMING_: false

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload check results
if: failure()
uses: actions/upload-artifact@v7
with:
name: cran-check-results
path: check
6 changes: 3 additions & 3 deletions R/knitr.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#' for an example.
#'
#' **Note:** When running chunks interactively in RStudio (e.g. when using
#' [R Notebooks](https://bookdown.org/yihui/rmarkdown/notebook.html)), it has
#' [R Notebooks](https://pkg.yihui.org/rmarkdown-book/notebook)), it has
#' been observed that the built-in, RStan-based engine is used for `stan`
#' chunks even when CmdStanR's engine has been registered in the session. When
#' the R Markdown document is knit/rendered, the correct engine is used. As a
Expand All @@ -37,8 +37,8 @@
#' `cmdstan` engine with `override = FALSE`.
#'
#' @references
#' * [Register a custom language engine for knitr](https://bookdown.org/yihui/rmarkdown-cookbook/custom-engine.html)
#' * [knitr's built-in Stan language engine](https://bookdown.org/yihui/rmarkdown/language-engines.html#stan)
#' * [Register a custom language engine for knitr](https://pkg.yihui.org/rmarkdown-cookbook/custom-engine)
#' * [knitr's built-in Stan language engine](https://pkg.yihui.org/rmarkdown-book/language-engines#stan)
#'
#' @seealso [eng_cmdstan()]
#'
Expand Down
6 changes: 3 additions & 3 deletions man/register_knitr_engine.Rd

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

4 changes: 1 addition & 3 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
library(testthat)
library(cmdstanr)

if (identical(Sys.getenv("NOT_CRAN"), "true")) {
test_check("cmdstanr")
}
test_check("cmdstanr")
6 changes: 6 additions & 0 deletions tests/testthat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ against a mocked CmdStan, so nothing is compiled. `test-model-rebuild.R`
compiles for real and checks the executable that results from a sequence of
calls.

Every file that needs CmdStan starts with `skip_on_cran()`, and a test
that needs CmdStan inside an otherwise pure file calls it itself, so on
CRAN, where nothing is installed, only the pure R tests run. The
`CRAN check` workflow runs the suite the same way, with no CmdStan
installed, so a missing skip fails there rather than on CRAN.

Files that compile call `set_cmdstan_path()` at the top. `with_mocked_cli()`
in `helper-mock-cli.R` stands in for `make` and for the executable's `info`
call, so a test can go through the build code without a compiler.
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-build-info.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ test_that("untracked dependencies are ordered by kind and deduplicated", {
})

test_that("a real user header is reported under dependencies and nowhere else", {
skip_on_cran()
stan_file <- file.path(withr::local_tempdir(), "bernoulli_external.stan")
file.copy(testing_stan_file("bernoulli_external"), stan_file)
header <- withr::local_tempfile(
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-build-record-compile.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()

# No C++ is compiled here: the mock writes a text file where make would have
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-cpp-options.R
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ data_file <- test_path("resources", "data", "bernoulli.data.json")
features <- function(mod) mod$.__enclos_env__$private$reported_features_

test_that("a feature inherited from make/local is reported, not requested", {
skip_on_cran()
stan_file <- file.path(withr::local_tempdir(), "bernoulli.stan")
file.copy(stan_program, stan_file)
threaded <- paste0(
Expand All @@ -331,6 +332,7 @@ test_that("a feature inherited from make/local is reported, not requested", {
})

test_that("an executable reporting no threading flag is unknown, not off", {
skip_on_cran()
stan_file <- file.path(withr::local_tempdir(), "bernoulli.stan")
file.copy(stan_program, stan_file)
info <- "stan_version_major=2\nstan_version_minor=39\nstan_version_patch=0"
Expand All @@ -350,6 +352,7 @@ test_that("an executable reporting no threading flag is unknown, not off", {
})

test_that("an executable adopted from live info reports threading as unknown", {
skip_on_cran()
stan_file <- file.path(withr::local_tempdir(), "bernoulli.stan")
file.copy(stan_program, stan_file)
info <- "stan_version_major=2\nstan_version_minor=39\nstan_version_patch=0"
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-csv.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
fit_bernoulli_optimize <- testing_fit("bernoulli", method = "optimize", seed = 1234)
fit_bernoulli_variational <- testing_fit("bernoulli", method = "variational", seed = 123)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-data.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
fit <- testing_fit("bernoulli", method = "sample", seed = 123)
fit_vb <- testing_fit("bernoulli", method = "variational", seed = 123)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-example.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ stan_program <- "
"

test_that("cmdstanr_example works", {
skip_on_cran()
fit_mcmc <- cmdstanr_example("logistic", chains = 2, force_recompile = TRUE)
checkmate::expect_r6(fit_mcmc, "CmdStanMCMC")
expect_equal(fit_mcmc$num_chains(), 2)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-failed-chains.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
stan_program <- testing_stan_file("chain_fails")
stan_program_init_warnings <- testing_stan_file("init_warnings")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-fit-gq.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
fit <- testing_fit("bernoulli", method = "sample", seed = 123)
fit_gq <- testing_fit("bernoulli_ppc", method = "generate_quantities", seed = 123, fitted_params = fit)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-fit-init.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()

data_list_schools <- testing_data("schools")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-fit-laplace.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
fit_laplace <- testing_fit("logistic", method = "laplace", seed = 100)
PARAM_NAMES <- c("alpha", "beta[1]", "beta[2]", "beta[3]")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-fit-mcmc.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
fit_mcmc <- testing_fit("logistic", method = "sample",
seed = 123, chains = 2, save_metric = FALSE)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-fit-mle.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
fit_mle <- testing_fit("logistic", method = "optimize", seed = 123)
mod <- testing_model("bernoulli")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-fit-shared.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
fits <- list()
fits[["sample"]] <- testing_fit("logistic", method = "sample",
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-fit-vb.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
fit_vb <- testing_fit("logistic", method = "variational", seed = 123)
fit_vb_sci_not <- testing_fit("logistic", method = "variational", seed = 123, iter = 200000, adapt_iter = 100000)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-install.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# avoid parallel on Mac due to strange intermittent TBB errors on Github Actions
skip_on_cran()

CORES <- if (os_is_macos()) 1 else 2

cmdstan_test_tarball_url <- Sys.getenv("CMDSTAN_TEST_TARBALL_URL")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-installation-check.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
stan_program <- testing_stan_file("bernoulli")

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-knitr.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test_that("eng_cmdstan throws correct errors", {
})

test_that("eng_cmdstan works", {
skip_on_cran()
skip_if_not_installed("knitr")
code <- "
parameters {
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-cmdstan-defaults.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
mod <- testing_model("bernoulli")

Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-code-print.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
stan_program <- testing_stan_file("bernoulli")
mod <- testing_model("bernoulli")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-compile-user_header.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

local_mocked_stanc <- function(.local_envir = parent.frame()) {
local_mocked_bindings(
get_cmdstan_flags = function(flag_name, ...) character(),
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-compile.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
stan_program <- cmdstan_example_file()
local_cmdstan_make_local(cpp_options = list("PRECOMPILED_HEADERS"="false"))
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-model-data.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# see separate test-json for testing writing data to JSON
skip_on_cran()

set_cmdstan_path()
mod <- testing_model("logistic")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-diagnose.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
mod <- testing_model("bernoulli")
data_list <- testing_data("bernoulli")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-expose-functions.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Standalone functions not expected to work on WSL yet
skip_on_cran()

skip_if(os_is_wsl())

set_cmdstan_path()
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-generate_quantities.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
fit <- testing_fit("bernoulli", method = "sample", seed = 123)
mod_gq <- testing_model("bernoulli_ppc")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-init.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
mod <- testing_model("bernoulli")
data_list <- testing_data("bernoulli")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-laplace.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
mod <- testing_model("logistic")
data_list <- testing_data("logistic")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-methods.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

skip_if(os_is_wsl())

set_cmdstan_path()
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-optimize.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
mod <- testing_model("bernoulli")
data_list <- testing_data("bernoulli")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-output_dir.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()

local_output_sandbox <- function(pattern = "sandbox", .local_envir = parent.frame()) {
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-pathfinder.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
stan_program <- testing_stan_file("bernoulli")
mod <- testing_model("bernoulli")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-rebuild-rules.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()

# The decision cmdstan_model() makes: build, reuse, or adopt. No C++ is
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-rebuild.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()

# A fresh copy of a resources/stan/ program (with its include file, for
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-sample-metric.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
mod <- testing_model("bernoulli")
data_list <- testing_data("bernoulli")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-sample.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
stan_program <- testing_stan_file("bernoulli")
mod <- testing_model("bernoulli")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-sample_mpi.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

test_that("sample_mpi() works", {
skip_if(!mpi_toolchain_present())
mpi_file <- write_stan_file("
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-stale-executable.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()

# What R/model.R's private assert_current() and its callers say about every
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-variables.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()

test_that("$variables() work correctly with example models", {
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-model-variational.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
mod <- testing_model("bernoulli")
data_list <- testing_data("bernoulli")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-opencl.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

set_cmdstan_path()
fit <- testing_fit("bernoulli", method = "sample", seed = 123, chains = 1)

Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-path.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_cran()

Sys.unsetenv("CMDSTAN")
PATH <- absolute_path(set_cmdstan_path())
VERSION <- cmdstan_version()
Expand Down
Loading
Loading