Skip to content

Commit 9801209

Browse files
authored
develop: use donttest to reduce runtime of examples (#15)
Also combine workflows that check the package into a single workflow.
1 parent 52d6b75 commit 9801209

13 files changed

Lines changed: 71 additions & 113 deletions
Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
pull_request:
44
branches: [main, dev]
55

6-
name: r-cmd-check
6+
name: check package
77

88
jobs:
99
r-cmd-check:
@@ -36,11 +36,38 @@ jobs:
3636

3737
- uses: r-lib/actions/setup-r-dependencies@v2
3838
with:
39-
extra-packages: any::rcmdcheck
40-
needs: check
39+
extra-packages: |
40+
any::lintr
41+
any::devtools
42+
any::rcmdcheck
43+
needs: check, lint
4144

4245
- uses: r-lib/actions/check-r-package@v2
4346
with:
4447
upload-snapshots: true
4548
args: 'c("--ignore-vignettes")'
46-
build_args: 'c("--no-build-vignettes")'
49+
build_args: 'c("--no-build-vignettes")'
50+
51+
# test that committed man pages and namespace are up to date
52+
- name: build roxygen documentation
53+
run: |
54+
cp -r man .man
55+
cp -r NAMESPACE .NAMESPACE
56+
make roxygen
57+
58+
- name: Check man pages
59+
run: diff -r man .man
60+
61+
- name: Check NAMESPACE
62+
run: diff -r NAMESPACE .NAMESPACE
63+
64+
- name: Lint package
65+
run: lintr::lint_package()
66+
shell: Rscript {0}
67+
env:
68+
LINTR_ERROR_ON_LINT: true
69+
70+
# test examples that have not been tested with r cmd check because of
71+
# \donttest
72+
- name: check examples
73+
run: make check-examples

.github/workflows/check-roxygen.yaml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.github/workflows/lint-project.yaml

Lines changed: 0 additions & 47 deletions
This file was deleted.

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ rmd:
6666
check: lint
6767
@_R_CHECK_FORCE_SUGGESTS_=0 echo 'future::plan("multicore"); res <- rcmdcheck::rcmdcheck(".", build_args=c("--no-build-vignettes"), args=c("--ignore-vignettes"))' | $(R)
6868

69+
check-examples:
70+
@_R_CHECK_FORCE_SUGGESTS_=0 echo 'future::plan("multicore"); devtools::run_examples(".", run_donttest = TRUE, run_dontrun = FALSE)' | $(R)
71+
6972
check-cran: build
7073
@$(R) CMD check $(BUILD_DIR)/$(PKG)_$(GETVER).tar.gz --timings --as-cran --no-multiarch --run-donttest
7174

R/Trial.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#' for decision-making
1212
#' @author Klaus Kähler Holst, Benedikt Sommer
1313
#' @examples
14-
#' \dontrun{
14+
#' \dontrun{ # don't run because of high computational time
1515
#' trial <- Trial$new(
1616
#' covariates = \(n) data.frame(a = rbinom(n, 1, 0.5), x = rnorm(n)),
1717
#' outcome = setargs(outcome_count, par = c(1, 0.5, 1), overdispersion = 0.7)
@@ -320,6 +320,7 @@ Trial <- R6::R6Class("Trial", #nolint
320320
#' the simulation. The return object is also assigned to the `estimates`
321321
#' field of this Trial class object (see examples).
322322
#' @examples
323+
#' \dontrun{ # don't run because of high computational time
323324
#' # future::plan("multicore")
324325
#' trial <- Trial$new(
325326
#' covariates = \(n) data.frame(a = rbinom(n, 1, 0.5)),
@@ -351,6 +352,7 @@ Trial <- R6::R6Class("Trial", #nolint
351352
#'
352353
#' # supplying another estimator
353354
#' trial$run(n = 100, R = 50, estimators = est_glm(robust = FALSE))
355+
#' }
354356
run = function(n, R = 100, estimators = NULL, ...) {
355357
return(trial_run(self, .private = private, n = n, R = R,
356358
estimators = estimators, ...)
@@ -364,6 +366,7 @@ Trial <- R6::R6Class("Trial", #nolint
364366
#' estimator. The behavior of passing arguments to lower level functions is
365367
#' identical to [Trial$run()][Trial].
366368
#' @examples
369+
#' \dontrun{ # don't run because of high computational time
367370
#' # toy examples with small number of Monte-Carlo replicates
368371
#' # future::plan("multicore")
369372
#' trial <- Trial$new(
@@ -387,6 +390,7 @@ Trial <- R6::R6Class("Trial", #nolint
387390
#' # supplying estimators to overrule previously set estimators
388391
#' trial$estimate_power(n = 100, R = 20,
389392
#' estimators = list(est_glm(), est_adj()))
393+
#' }
390394
#' @return numeric
391395
estimate_power = function(n, R = 100, estimators = NULL,
392396
summary.args = list(), ...) {
@@ -434,7 +438,7 @@ Trial <- R6::R6Class("Trial", #nolint
434438
#' @return samplesize_estimate S3 object
435439
#' @author Klaus Kähler Holst
436440
#' @examples
437-
#' \dontrun{
441+
#' \dontrun{ # don't run because of high computational time
438442
#' trial <- Trial$new(
439443
#' covariates = \(n) data.frame(a = rbinom(n, 1, 0.5)),
440444
#' outcome = \(data, ate, sd) with(data, rnorm(nrow(data), a * ate, sd)),
@@ -449,11 +453,11 @@ Trial <- R6::R6Class("Trial", #nolint
449453
#'
450454
#' # reduce number of iterations for bisection step but keep R = 100
451455
#' # (default value)
452-
#' trial$estimate_samplesize(bisection.control = list(niter = 2))
456+
#' # trial$estimate_samplesize(bisection.control = list(niter = 2))
453457
#'
454458
#' # reduce significance level from 0.05 to 0.025, but keep alternative as
455459
#' # before
456-
#' trial$estimate_samplesize(summary.args = list(level = 0.025))
460+
#' # trial$estimate_samplesize(summary.args = list(level = 0.025))
457461
#' }
458462
estimate_samplesize = function(
459463
...,

R/carts-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#' @useDynLib carts, .registration=TRUE
2525
#' @author Benedikt Sommer, Klaus Holst, Foroogh Shamsi
2626
#' @examples
27-
#' \dontrun{
27+
#' \dontrun{ # don't run because of high computational time
2828
#' trial <- Trial$new(
2929
#' covariates = \(n) data.frame(a = rbinom(n, 1, 0.5), x = rnorm(n)),
3030
#' outcome = setargs(outcome_count, par = c(1, 0.5, 1), overdispersion = 0.7)

R/estimators.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#' @author Klaus Kähler Holst
2121
#' @export
2222
#' @examples
23+
#' \dontrun{
2324
#' trial <- Trial$new(
2425
#' covariates = function(n) data.frame(a = rbinom(n, 1, 0.5), x = rnorm(n)),
2526
#' outcome = setargs(outcome_count,
@@ -57,6 +58,7 @@
5758
#' # regression coefficient changes when encoding the treatment variable as a
5859
#' # factor
5960
#' est_glm(family = poisson, target.parameter = "a1")(dd_factor)
61+
#' }
6062
est_glm <- function(response = "y",
6163
treatment = "a",
6264
covariates = NULL,
@@ -164,6 +166,7 @@ est_glmbin <- function(...) {
164166
#' @author Klaus Kähler Holst
165167
#' @export
166168
#' @examples
169+
#' \dontrun{ # don't run because of high computational time
167170
#' trial <- Trial$new(
168171
#' covariates = function(n) data.frame(a = rbinom(n, 1, 0.5), x = rnorm(n)),
169172
#' outcome = setargs(outcome_count,
@@ -208,6 +211,7 @@ est_glmbin <- function(...) {
208211
#'
209212
#' dd_factor$a <- factor(dd_factor$a, levels = c(1, 0))
210213
#' estimator(dd_factor) # E[Y(1)] - E[Y(0)]
214+
#' }
211215
est_adj <- function(response = "y",
212216
treatment = "a",
213217
covariates = NULL,

R/outcome_models.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ outcome_continuous <- function(data,
318318
#' @seealso [outcome_count] [outcome_lp] [outcome_binary] [outcome_continuous]
319319
#' @examples
320320
#' \dontrun{
321+
#' outcome_phreg <- carts:::outcome_phreg
321322
#' library("survival")
322323
#' data(pbc, package = "survival")
323324
#' pbc0 <- na.omit(pbc) |>

man/Trial.Rd

Lines changed: 17 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/carts-package.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)