diff --git a/.Rbuildignore b/.Rbuildignore index 4499be5..e246955 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,8 @@ README.html ^docs$ ^pkgdown$ ^\.github$ +^\.pre-commit-config\.yaml$ +^\.githooks$ +^README\.rmd$ +^tools$ +^cran-plan\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index fcefd43..f074586 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,33 +1,34 @@ Package: chefCriteria -Title: A collection of {chef} criterion functions -Version: 0.0.1.9000 -Authors@R: +Title: A Collection of 'chef' Criterion Functions +Version: 0.1.0 +Authors@R: c(person("MEWP (Matthew David Phelps)", , , "mewp@novonordisk.com", role = c("aut")), person("NOSJ (Nicolai Skov Johnsen)",, , "nosj@novonordisk.com", role = c("aut")), person("HSPU (Henrik Sparre Spiegelhauer)",, , "hspu@novonordisk.com", role = c("aut")), person("CINO (Christian Haargaard Olsen)",, , "cino@novonordisk.com", role = c("aut", "cre"))) -Description: A collection of criterion functions for statistical evidence generation with {chef}. +Description: Provides a collection of criterion functions for use with the 'chef' + pipeline framework for clinical trial evidence generation. Criterion functions + determine whether a statistical analysis should be included in the final output + based on conditions such as minimum subject counts or p-value thresholds. + Designed for use in healthcare technology assessments such as AMNOG dossier + submissions. License: MIT + file LICENSE +BugReports: https://github.com/hta-pharma/chefCriteria/issues Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 Config/testthat/edition: 3 -Imports: - chef, +Remotes: + hta-pharma/chef@feature/CRAN_submission, + hta-pharma/chefStats@feature/CRAN_submission +Imports: chefStats, - data.table (>= 1.14.2), - magrittr, - purrr, - dplyr, - knitr -Suggests: + data.table (>= 1.14.2) +Suggests: + chef, testthat (>= 3.0.0), - pharmaverseadam -Remotes: - hta-pharma/chefStats, - hta-pharma/chef -VignetteBuilder: - knitr -URL: - https://hta-pharma.github.io/chefCriteria/, - https://app.codecov.io/gh/hta-pharma/chefCriteria + pharmaverseadam, + dplyr, + purrr +URL: https://hta-pharma.github.io/chefCriteria/, + https://github.com/hta-pharma/chefCriteria diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..54c76bb --- /dev/null +++ b/NEWS.md @@ -0,0 +1,5 @@ +# chefCriteria 0.1.0 + +* Initial CRAN submission. +* Provides `crit_bb_nsubev_01()`, `crit_bb_pval_01()`, and `crit_ep_nsubev_01()` + as inclusion criterion functions for use with the `chef` pipeline framework. diff --git a/R/crit_by_strata_by_trt.R b/R/crit_by_strata_by_trt.R index 04c58bd..b59f35f 100644 --- a/R/crit_by_strata_by_trt.R +++ b/R/crit_by_strata_by_trt.R @@ -14,6 +14,16 @@ #' @return A Boolean value indicating whether the criterion is met. #' @export #' @import data.table +#' @examples +#' dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3", "S4")) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' # Returns TRUE: 2 subjects with events >= minimum of 2 +#' crit_bb_nsubev_01(dat, event_index = c(1L, 2L), +#' subjectid_var = "USUBJID", n_subj_event_min = 2L) +#' # Returns FALSE: 1 subject with events < minimum of 2 +#' crit_bb_nsubev_01(dat, event_index = c(1L), +#' subjectid_var = "USUBJID", n_subj_event_min = 2L) crit_bb_nsubev_01 <- function(dat, event_index, subjectid_var, n_subj_event_min, ...){ # Evaluate criterion @@ -35,7 +45,7 @@ crit_bb_nsubev_01 <- function(dat, event_index, subjectid_var, n_subj_event_min, #' `dat`. #' @param cell_index A vector of integers referencing the rows of `dat` (as #' specified by the `INDEX_` column in `dat`) that match the population to be -#' analyzed. See the "Endpoint Events" vignette in {ramnog} +#' analyzed. See the "Endpoint Events" vignette in \pkg{ramnog} #' for more information. #' @param treatment_var character. The name of the treatment variable in `dat`. #' @param treatment_refval character. The reference value of the treatment variable in `dat`. @@ -45,6 +55,17 @@ crit_bb_nsubev_01 <- function(dat, event_index, subjectid_var, n_subj_event_min, #' #' @return A Boolean value indicating whether the criterion is met. #' @export +#' @examples +#' dat <- data.table::data.table( +#' USUBJID = c("S1", "S2", "S3", "S4", "S5", "S6"), +#' TRT = c("Active", "Active", "Active", "Placebo", "Placebo", "Placebo") +#' ) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' crit_bb_pval_01(dat, event_index = c(1L, 2L, 4L), +#' cell_index = dat[["INDEX_"]], +#' treatment_var = "TRT", treatment_refval = "Placebo", +#' subjectid_var = "USUBJID", pval_max = 0.05) crit_bb_pval_01 <- function(dat, event_index, diff --git a/R/crit_endpoint.R b/R/crit_endpoint.R index 19dd86d..57e0e89 100644 --- a/R/crit_endpoint.R +++ b/R/crit_endpoint.R @@ -15,6 +15,17 @@ #' @return A Boolean value indicating whether the criterion is met. #' @import data.table #' @export +#' @examples +#' dat <- data.table::data.table( +#' USUBJID = c("S1", "S2", "S3", "S4"), +#' TRT = c("Active", "Active", "Placebo", "Placebo") +#' ) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' # Returns TRUE: Active arm has 2 subjects with events >= minimum of 2 +#' crit_ep_nsubev_01(dat, event_index = c(1L, 2L), +#' subjectid_var = "USUBJID", +#' treatment_var = "TRT", n_subj_event_min = 2L) crit_ep_nsubev_01 <- function(dat, event_index, subjectid_var, diff --git a/man/crit_bb_nsubev_01.Rd b/man/crit_bb_nsubev_01.Rd index 2d84de6..2fde18f 100644 --- a/man/crit_bb_nsubev_01.Rd +++ b/man/crit_bb_nsubev_01.Rd @@ -25,3 +25,14 @@ A Boolean value indicating whether the criterion is met. \description{ This function checks if the number of subjects with events in the total population is greater than or equal to a specified minimum. } +\examples{ +dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3", "S4")) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +# Returns TRUE: 2 subjects with events >= minimum of 2 +crit_bb_nsubev_01(dat, event_index = c(1L, 2L), + subjectid_var = "USUBJID", n_subj_event_min = 2L) +# Returns FALSE: 1 subject with events < minimum of 2 +crit_bb_nsubev_01(dat, event_index = c(1L), + subjectid_var = "USUBJID", n_subj_event_min = 2L) +} diff --git a/man/crit_bb_pval_01.Rd b/man/crit_bb_pval_01.Rd index 3aabe9e..6d33ba1 100644 --- a/man/crit_bb_pval_01.Rd +++ b/man/crit_bb_pval_01.Rd @@ -24,7 +24,7 @@ the definition of an 'event'. Matching is done via the \code{INDEX_} column in \item{cell_index}{A vector of integers referencing the rows of \code{dat} (as specified by the \code{INDEX_} column in \code{dat}) that match the population to be -analyzed. See the "Endpoint Events" vignette in {ramnog} +analyzed. See the "Endpoint Events" vignette in \pkg{ramnog} for more information.} \item{treatment_var}{character. The name of the treatment variable in \code{dat}.} @@ -43,3 +43,15 @@ A Boolean value indicating whether the criterion is met. \description{ This function checks if the p-value in the total population is below a specified maximum. } +\examples{ +dat <- data.table::data.table( + USUBJID = c("S1", "S2", "S3", "S4", "S5", "S6"), + TRT = c("Active", "Active", "Active", "Placebo", "Placebo", "Placebo") +) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +crit_bb_pval_01(dat, event_index = c(1L, 2L, 4L), + cell_index = dat[["INDEX_"]], + treatment_var = "TRT", treatment_refval = "Placebo", + subjectid_var = "USUBJID", pval_max = 0.05) +} diff --git a/man/crit_ep_nsubev_01.Rd b/man/crit_ep_nsubev_01.Rd index 38156d9..7985793 100644 --- a/man/crit_ep_nsubev_01.Rd +++ b/man/crit_ep_nsubev_01.Rd @@ -34,3 +34,15 @@ A Boolean value indicating whether the criterion is met. \description{ This function checks if the number of subjects with events in at least one study arm is greater than or equal to a specified minimum. } +\examples{ +dat <- data.table::data.table( + USUBJID = c("S1", "S2", "S3", "S4"), + TRT = c("Active", "Active", "Placebo", "Placebo") +) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +# Returns TRUE: Active arm has 2 subjects with events >= minimum of 2 +crit_ep_nsubev_01(dat, event_index = c(1L, 2L), + subjectid_var = "USUBJID", + treatment_var = "TRT", n_subj_event_min = 2L) +} diff --git a/tools/strip-remotes.R b/tools/strip-remotes.R new file mode 100644 index 0000000..9b512f9 --- /dev/null +++ b/tools/strip-remotes.R @@ -0,0 +1,68 @@ +#!/usr/bin/env Rscript +# Strip the `Remotes:` block from DESCRIPTION before building a CRAN tarball. +# +# Remotes is used during CI/development so dependent packages can pull +# unreleased versions of sibling packages from GitHub. CRAN rejects any +# package whose DESCRIPTION contains a Remotes field, so it must be removed +# from the tarball that is submitted. +# +# Usage (from the package root): +# Rscript tools/strip-remotes.R # rewrites DESCRIPTION in place +# Rscript tools/strip-remotes.R --build # also runs R CMD build on the cleaned source +# +# The --build flag produces _.tar.gz in the parent directory +# (R CMD build's default), then restores DESCRIPTION so the working tree +# is left as it was. + +args <- commandArgs(trailingOnly = TRUE) +do_build <- "--build" %in% args + +desc_path <- "DESCRIPTION" +if (!file.exists(desc_path)) { + stop("DESCRIPTION not found. Run this script from the package root.") +} + +original <- readLines(desc_path, warn = FALSE) + +# A DESCRIPTION field starts at column 1; continuation lines are indented. +# Drop the line matching `^Remotes:` and any continuation lines that follow. +field_start <- grepl("^[^[:space:]]", original) +remotes_idx <- which(grepl("^Remotes:", original)) + +if (length(remotes_idx) == 0) { + message("No Remotes: field found in DESCRIPTION; nothing to strip.") + cleaned <- original +} else { + drop <- integer() + for (i in remotes_idx) { + drop <- c(drop, i) + j <- i + 1L + while (j <= length(original) && !field_start[j]) { + drop <- c(drop, j) + j <- j + 1L + } + } + cleaned <- original[-drop] + message("Stripped Remotes block (", length(drop), " line(s)).") +} + +if (do_build) { + # Snapshot the original so we can restore it after R CMD build. + backup <- tempfile("DESCRIPTION-") + file.copy(desc_path, backup, overwrite = TRUE) + on.exit({ + file.copy(backup, desc_path, overwrite = TRUE) + unlink(backup) + message("Restored original DESCRIPTION.") + }, add = TRUE) + + writeLines(cleaned, desc_path) + status <- system2("R", c("CMD", "build", ".")) + if (status != 0) { + stop("R CMD build failed (exit ", status, ").") + } +} else { + writeLines(cleaned, desc_path) + message("DESCRIPTION rewritten in place. Re-run with --build to produce a tarball,", + " or restore from git when done submitting.") +}