From 3c57cc3b4e270be5f36f8cd7dc5dc2a76ad640d7 Mon Sep 17 00:00:00 2001 From: "CINO (Christian Haargaard Olsen)" Date: Thu, 16 Apr 2026 15:12:45 +0200 Subject: [PATCH 1/7] Remove testr dependency for CRAN submission - Remove Remotes block from DESCRIPTION - Remove testr from Suggests, add withr - Fix DescTools indentation in Imports - Replace testr::create_local_project() in test-use_chefStats.R with withr::local_tempdir() + withr::local_dir() Co-Authored-By: Claude Sonnet 4.6 --- DESCRIPTION | 9 +++------ tests/testthat/test-use_chefStats.R | 7 ++++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index deba68d..11685a9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,6 @@ Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 Suggests: - testr, covr, pkgdown, testthat, @@ -39,7 +38,8 @@ Suggests: pharmaverseadam, tidyr, purrr, - kableExtra + kableExtra, + withr Imports: Barnard, stats, @@ -48,10 +48,7 @@ Imports: checkmate, cli, usethis, - DescTools -Remotes: - hta-pharma/chef, - matthew-phelps/testr + DescTools Config/testthat/edition: 3 VignetteBuilder: knitr Config/testthat/parallel: true diff --git a/tests/testthat/test-use_chefStats.R b/tests/testthat/test-use_chefStats.R index e8eb7d0..bc10f8a 100644 --- a/tests/testthat/test-use_chefStats.R +++ b/tests/testthat/test-use_chefStats.R @@ -1,6 +1,7 @@ test_that("use_chefStats errors when given function name that already exists", { - testr::create_local_project() + tmp <- withr::local_tempdir() + dir.create(file.path(tmp, "R")) + withr::local_dir(tmp) dump("n_subj", file = "R/test.R") - expect_error(use_chefStats(fn_name = "n_subj",fn_type = "stat_by_strata_by_trt"),regexp = "The function name") - + expect_error(use_chefStats(fn_name = "n_subj", fn_type = "stat_by_strata_by_trt"), regexp = "The function name") }) From 9d949d95859fda6cac62a921264edfad3088281e Mon Sep 17 00:00:00 2001 From: "CINO (Christian Haargaard Olsen)" Date: Thu, 16 Apr 2026 15:13:53 +0200 Subject: [PATCH 2/7] Fix DESCRIPTION metadata for CRAN submission - Title case: "Provide Methods for Different Statistics" - Expand Description to 3 sentences - Add BugReports field - Remove redundant Maintainer field (Authors@R cre role is sufficient) - Tidy URL field indentation, remove codecov URL Co-Authored-By: Claude Sonnet 4.6 --- DESCRIPTION | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 11685a9..8f5db2c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: chefStats -Title: Provide methods for different statistics +Title: Provide Methods for Different Statistics Version: 0.1.1 Authors@R: c(person(given = "Matthew David Phelps", @@ -22,9 +22,13 @@ Authors@R: email = "cino@novonordisk.com"), person(given = "Novo Nordisk A/S", role = "cph")) -Maintainer: Christian Haargaard Olsen -Description: Provide a library of methods that can be used to calculate different statistics. +Description: Provides a library of statistical methods for use in clinical trial evidence + generation workflows. Functions cover subject counts, event rates, odds ratios, + relative risks, risk differences, p-values, and demographic summaries, all + formatted for use with the 'chef' pipeline framework. Designed to support + healthcare technology assessments such as AMNOG dossier submissions. License: MIT + file LICENSE +BugReports: https://github.com/hta-pharma/chefStats/issues Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 @@ -52,7 +56,5 @@ Imports: Config/testthat/edition: 3 VignetteBuilder: knitr Config/testthat/parallel: true -URL: - https://hta-pharma.github.io/chefStats/, - https://github.com/hta-pharma/chefStats, - https://app.codecov.io/github/hta-pharma/chefStats +URL: https://hta-pharma.github.io/chefStats/, + https://github.com/hta-pharma/chefStats From 03a26ab6838a8ee1523444dcee6c53a7d677ebf5 Mon Sep 17 00:00:00 2001 From: "CINO (Christian Haargaard Olsen)" Date: Thu, 16 Apr 2026 15:16:33 +0200 Subject: [PATCH 3/7] Mark barnard_test_ and breslowdaytest_ as internal These functions have man pages but are not exported. Adding @keywords internal suppresses the R CMD check note about objects in 'man' that are not exported. Co-Authored-By: Claude Sonnet 4.6 --- R/BreslowDayFunction.R | 1 + R/barnard_test.R | 1 + man/barnard_test_.Rd | 1 + man/breslowdaytest_.Rd | 1 + 4 files changed, 4 insertions(+) diff --git a/R/BreslowDayFunction.R b/R/BreslowDayFunction.R index 1ffb68a..5d1349d 100644 --- a/R/BreslowDayFunction.R +++ b/R/BreslowDayFunction.R @@ -7,6 +7,7 @@ #' @return A vector with three values statistic - Breslow and Day test #' statistic pval - p value evtl. based on the Tarone test statistic using a #' \eqn{\chi^2(K-1)} distribution +#' @keywords internal breslowdaytest_ <- function(x, odds_ratio = NA, correct = FALSE) { # Call the BreslowDayTest from the DescTools package diff --git a/R/barnard_test.R b/R/barnard_test.R index 4dc2c34..89b85c0 100644 --- a/R/barnard_test.R +++ b/R/barnard_test.R @@ -8,6 +8,7 @@ #' error (default), or return an NA (safe_mode = FALSE) #' #' @return 2-sided p-value for the Barnards Unconditional Exact test +#' @keywords internal #' @importFrom Barnard barnard.test barnard_test_ <- diff --git a/man/barnard_test_.Rd b/man/barnard_test_.Rd index c4e6f1c..52f3c76 100644 --- a/man/barnard_test_.Rd +++ b/man/barnard_test_.Rd @@ -22,3 +22,4 @@ error (default), or return an NA (safe_mode = FALSE)} \description{ Barnards Unconditional Exact Test with trial data } +\keyword{internal} diff --git a/man/breslowdaytest_.Rd b/man/breslowdaytest_.Rd index 2e281be..2a49374 100644 --- a/man/breslowdaytest_.Rd +++ b/man/breslowdaytest_.Rd @@ -21,3 +21,4 @@ statistic pval - p value evtl. based on the Tarone test statistic using a \description{ Breslow-Day test } +\keyword{internal} From 265b12a842628abd5a7547a97c8560d975c7339d Mon Sep 17 00:00:00 2001 From: "CINO (Christian Haargaard Olsen)" Date: Thu, 16 Apr 2026 15:49:55 +0200 Subject: [PATCH 4/7] Add examples to all exported functions and fix duplicate mean_value - Add \examples{} to all 25 exported .Rd files - Add @examples to all corresponding R source files - Remove duplicate mean_value definition from by_strata_by_trt.R (first definition had wrong @return description and used J() instead of list() for key lookup; second definition is the correct one) - Clean up duplicate \usage{} and \value{} entries in mean_value.Rd Co-Authored-By: Claude Sonnet 4.6 --- R/across_strata_across_trt.R | 20 ++++- R/building_blocks.R | 29 ++++++- R/by_strata_across_trt.R | 40 +++++++++ R/by_strata_by_trt.R | 146 ++++++++++++++++++++++----------- R/two_by_two_x.R | 25 +++++- R/use_chefStats.R | 5 +- man/OR.Rd | 11 +++ man/RD.Rd | 11 +++ man/RR.Rd | 11 +++ man/count_set.Rd | 7 ++ man/demographics_continuous.Rd | 11 +++ man/demographics_counts.Rd | 12 +++ man/hedges_g.Rd | 8 ++ man/make_two_by_two_.Rd | 12 +++ man/make_two_by_two_by_k_.Rd | 14 ++++ man/mean_value.Rd | 14 +++- man/n_event.Rd | 7 ++ man/n_event_.Rd | 6 ++ man/n_event_100y.Rd | 13 +++ man/n_subj.Rd | 6 ++ man/n_subj_.Rd | 9 ++ man/n_subj_event.Rd | 7 ++ man/n_subj_event_.Rd | 6 ++ man/obs_time_by_trt.Rd | 9 ++ man/p_subj_event.Rd | 7 ++ man/p_subj_event_.Rd | 7 ++ man/p_subj_event_by_trt.Rd | 12 +++ man/p_val.Rd | 11 +++ man/p_val_interaction.Rd | 13 +++ man/sd_value.Rd | 10 +++ man/use_chefStats.Rd | 5 ++ 31 files changed, 446 insertions(+), 58 deletions(-) diff --git a/R/across_strata_across_trt.R b/R/across_strata_across_trt.R index 3ba2743..cf9121c 100644 --- a/R/across_strata_across_trt.R +++ b/R/across_strata_across_trt.R @@ -14,6 +14,18 @@ #' #' @return A data.table containing the statistics for p-value interaction tests. #' @export +#' @examples +#' dat <- data.table::data.table( +#' USUBJID = c("S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8"), +#' TRT = c("Active", "Active", "Active", "Active", +#' "Placebo", "Placebo", "Placebo", "Placebo"), +#' STRATA = c("M", "M", "F", "F", "M", "M", "F", "F") +#' ) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' p_val_interaction(dat, event_index = c(1L, 3L, 5L, 7L), +#' treatment_var = "TRT", treatment_refval = "Placebo", +#' subjectid_var = "USUBJID", strata_var = "STRATA") p_val_interaction <- function(dat, event_index, treatment_var, @@ -69,7 +81,13 @@ p_val_interaction <- function(dat, #' @param ... optional arguments to #' @return A list containing Hedges G statistics. #' @export -#' +#' @examples +#' dat <- data.table::data.table( +#' treatment_val = c("Active", "Active", "Active", "Placebo", "Placebo", "Placebo"), +#' stat_var = rep(c("N_sub", "mean_value", "sd_value"), 2), +#' stat_val = c(50, 12.3, 2.1, 50, 10.1, 2.5) +#' ) +#' hedges_g(dat, reference_val = "Placebo") hedges_g <- function(dat, reference_val, safe_mode = FALSE, ...) { n_trt <- diff --git a/R/building_blocks.R b/R/building_blocks.R index 3c59b30..ef025af 100644 --- a/R/building_blocks.R +++ b/R/building_blocks.R @@ -10,7 +10,14 @@ #' #' @return An integer #' @export -#' +#' @examples +#' dat <- data.table::data.table( +#' USUBJID = c("S1", "S2", "S3"), +#' VALUE = c(1.1, 2.2, 3.3) +#' ) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' n_subj_(dat, cell_index = dat[["INDEX_"]], subjectid_var = "USUBJID") n_subj_ <- function(dat, cell_index, @@ -28,7 +35,11 @@ n_subj_ <- #' #' @return an integer value #' @export -#' +#' @examples +#' dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3")) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' n_event_(dat, intersect_index = c(1L, 2L)) n_event_ <- function(dat, intersect_index) { dat[list(intersect_index)] |> NROW() @@ -46,7 +57,11 @@ n_event_ <- function(dat, intersect_index) { #' #' @return an interger value #' @export -#' +#' @examples +#' dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3")) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' n_subj_event_(dat, intersect_index = c(1L, 2L), subjectid_var = "USUBJID") n_subj_event_ <- function(dat, intersect_index, subjectid_var) { dat[list(intersect_index)] |> data.table::uniqueN(by = subjectid_var) @@ -66,7 +81,13 @@ n_subj_event_ <- function(dat, intersect_index, subjectid_var) { #' the data (default is "USUBJID"). #' #' @return an integer value -#' @export +#' @export +#' @examples +#' dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3")) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' p_subj_event_(dat, cell_index = 1:3, intersect_index = c(1L, 2L), +#' subjectid_var = "USUBJID") p_subj_event_ <- function(dat, cell_index, diff --git a/R/by_strata_across_trt.R b/R/by_strata_across_trt.R index 9a036a6..b6f194e 100644 --- a/R/by_strata_across_trt.R +++ b/R/by_strata_across_trt.R @@ -18,6 +18,16 @@ #' #' @return A data.table containing Relative Risk statistics. #' @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_) +#' RR(dat, event_index = c(1L, 2L, 4L), cell_index = dat[["INDEX_"]], +#' treatment_var = "TRT", treatment_refval = "Placebo", +#' subjectid_var = "USUBJID") RR <- function(dat, event_index, cell_index, @@ -75,6 +85,16 @@ RR <- function(dat, #' #' @return A data.table containing Odds Ratio statistics. #' @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_) +#' OR(dat, event_index = c(1L, 2L, 4L), cell_index = dat[["INDEX_"]], +#' treatment_var = "TRT", treatment_refval = "Placebo", +#' subjectid_var = "USUBJID") OR <- function(dat, event_index, cell_index, @@ -134,6 +154,16 @@ OR <- function(dat, #' #' @return A data.table containing Risk Difference statistics. #' @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_) +#' RD(dat, event_index = c(1L, 2L, 4L), cell_index = dat[["INDEX_"]], +#' treatment_var = "TRT", treatment_refval = "Placebo", +#' subjectid_var = "USUBJID") RD <- function(dat, event_index, cell_index, @@ -196,6 +226,16 @@ RD <- function(dat, #' @param ... Optional parameters. #' @return A data.table containing p-value statistics. #' @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_) +#' p_val(dat, event_index = c(1L, 2L, 4L), cell_index = dat[["INDEX_"]], +#' treatment_var = "TRT", treatment_refval = "Placebo", +#' subjectid_var = "USUBJID") p_val <- function(dat, event_index, diff --git a/R/by_strata_by_trt.R b/R/by_strata_by_trt.R index ed813d7..ba93e71 100644 --- a/R/by_strata_by_trt.R +++ b/R/by_strata_by_trt.R @@ -13,6 +13,11 @@ #' @return A data.table containing the number of subjects for the given combination of treatment and stratum. #' @export #' @import data.table +#' @examples +#' dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3")) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' n_subj(dat, cell_index = dat[["INDEX_"]], subjectid_var = "USUBJID") n_subj <- function(dat, cell_index, subjectid_var, @@ -49,6 +54,12 @@ n_subj <- function(dat, #' #' @return A data.table containing the number of events for the given combination of treatment and stratum. #' @export +#' @examples +#' dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3", "S4")) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' n_event(dat, event_index = c(1L, 2L), cell_index = dat[["INDEX_"]], +#' subjectid_var = "USUBJID") n_event <- function(dat, event_index, @@ -87,6 +98,12 @@ n_event <- #' #' @return A data.table containing the number of subjects with events for the given combination of treatment and stratum. #' @export +#' @examples +#' dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3", "S4")) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' n_subj_event(dat, event_index = c(1L, 2L), cell_index = dat[["INDEX_"]], +#' subjectid_var = "USUBJID") n_subj_event <- function(dat, event_index, @@ -127,6 +144,12 @@ n_subj_event <- #' #' @return A data.table containing the percentage of subjects with events for the given combination of treatment and stratum #' @export +#' @examples +#' dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3", "S4")) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' p_subj_event(dat, event_index = c(1L, 2L), cell_index = dat[["INDEX_"]], +#' subjectid_var = "USUBJID") p_subj_event <- function(dat, event_index, @@ -176,6 +199,12 @@ p_subj_event <- #' @param ... Optional parameters. #' @return a data.table containing all statistical outputs #' @export +#' @examples +#' dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3", "S4")) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' count_set(dat, event_index = c(1L, 2L), cell_index = dat[["INDEX_"]], +#' subjectid_var = "USUBJID") count_set <- function(dat, event_index, cell_index, @@ -232,6 +261,16 @@ count_set <- function(dat, #' #' @return A data.table containing the summary statistics for the given continuous variable in the analysis data set. #' @export +#' @examples +#' dat <- data.table::data.table( +#' USUBJID = c("S1", "S2", "S3", "S4"), +#' AGE = c(45, 52, 60, 38) +#' ) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' demographics_continuous(dat, event_index = dat[["INDEX_"]], +#' cell_index = dat[["INDEX_"]], +#' subjectid_var = "USUBJID", var = "AGE") demographics_continuous <- function(dat, event_index, cell_index, @@ -282,7 +321,17 @@ demographics_continuous <- function(dat, #' #' @return A data.table containing the summary statistics. #' @export -#' +#' @examples +#' dat <- data.table::data.table( +#' USUBJID = c("S1", "S2", "S3", "S4"), +#' SEX = c("M", "F", "M", NA_character_) +#' ) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' demographics_counts(dat, cell_index = dat[["INDEX_"]], +#' subjectid_var = "USUBJID", +#' stratify_by = c("TOTAL_", "SEX"), +#' strata_var = "SEX") demographics_counts <- function(dat, cell_index, subjectid_var, @@ -336,49 +385,6 @@ total_missing_counts <- function(dat_cell, stratify_by) { out[] } - -#' Calculate mean value -#' -#' @description Calculate the mean value of a variable -#' -#' @param dat data.table. The analysis data set. -#' @param event_index vector of integers that index the rows in `dat` that match -#' the definition of an 'event'. Matching is done via the `INDEX_` column in -#' `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} -#' for more information. -#' @param subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). -#' @param var character. Name of the variable in the analysis data that is subject to the statistics. -#' @param ... Optional parameters. -#' -#' @return A data.table containing the percentage of subjects with events by treatment. -#' @export -#' -mean_value <- function(dat, - event_index, - cell_index, - subjectid_var, - var, - ...) { - intersect_index <- intersect(cell_index, event_index) - dat_cell <- dat[J(intersect_index)] |> - unique(by = c(subjectid_var)) - - stat <- dat_cell[[var]] |> - mean() - - return( - data.table( - label = "mean", - description = "Summary statistics", - qualifiers = var, - value = stat - ) - ) -} - #' Calculate percentage of subjects with events #' #' @description Calculate the percentage of subjects with events by treatment and strata. @@ -398,6 +404,17 @@ mean_value <- function(dat, #' #' @return A data.table containing the percentage of subjects with events by treatment. #' @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_) +#' p_subj_event_by_trt(dat, event_index = c(1L, 2L), +#' cell_index = dat[TRT == "Active"][["INDEX_"]], +#' subjectid_var = "USUBJID", +#' treatment_var = "TRT", treatment_value = "Active") p_subj_event_by_trt <- function(dat, event_index, @@ -447,7 +464,14 @@ p_subj_event_by_trt <- #' #' @return A data.table containing the observation time by treatment. #' @export -#' +#' @examples +#' dat <- data.table::data.table( +#' USUBJID = c("S1", "S2", "S3"), +#' INTRDURY = c(1.5, 2.0, 0.8) +#' ) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' obs_time_by_trt(dat, cell_index = dat[["INDEX_"]], subjectid_var = "USUBJID") obs_time_by_trt <- function(dat, cell_index, subjectid_var, @@ -485,6 +509,18 @@ obs_time_by_trt <- function(dat, #' #' @return A data.table containing the number of events per 100 years of exposure. #' @export +#' @examples +#' dat <- data.table::data.table( +#' USUBJID = c("S1", "S2", "S3", "S4"), +#' TRT = c("Active", "Active", "Placebo", "Placebo"), +#' INTRDURY = c(1.5, 2.0, 0.8, 1.2) +#' ) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' n_event_100y(dat, event_index = c(1L, 2L), +#' cell_index = dat[TRT == "Active"][["INDEX_"]], +#' subjectid_var = "USUBJID", +#' treatment_var = "TRT", treatment_value = "Active") n_event_100y <- function(dat, event_index, cell_index, @@ -529,7 +565,15 @@ n_event_100y <- function(dat, #' #' @return A data.table containing the mean value. #' @export -#' +#' @examples +#' dat <- data.table::data.table( +#' USUBJID = c("S1", "S2", "S3"), +#' AVAL = c(1.5, 2.5, 3.5) +#' ) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' mean_value(dat, event_index = dat[["INDEX_"]], cell_index = dat[["INDEX_"]], +#' subjectid_var = "USUBJID", var = "AVAL") mean_value <- function(dat, event_index, cell_index, @@ -568,7 +612,15 @@ mean_value <- function(dat, #' #' @return A data.table containing the standard deviation. #' @export -#' +#' @examples +#' dat <- data.table::data.table( +#' USUBJID = c("S1", "S2", "S3"), +#' AVAL = c(1.5, 2.5, 3.5) +#' ) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' sd_value(dat, event_index = dat[["INDEX_"]], cell_index = dat[["INDEX_"]], +#' subjectid_var = "USUBJID", var = "AVAL") sd_value <- function(dat, event_index, cell_index, diff --git a/R/two_by_two_x.R b/R/two_by_two_x.R index 7d0eb9d..995863d 100644 --- a/R/two_by_two_x.R +++ b/R/two_by_two_x.R @@ -26,7 +26,17 @@ #' @return A matrix #' @export #' @importFrom magrittr %>% -#' +#' @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_) +#' make_two_by_two_(dat, event_index = c(1L, 2L, 4L), +#' cell_index = dat[["INDEX_"]], +#' treatment_var = "TRT", treatment_refval = "Placebo", +#' subjectid_var = "USUBJID") make_two_by_two_ <- function(dat, event_index, @@ -137,6 +147,19 @@ ensure_complete_two_by_two <- function(two_by_two_long, treatment_var) { #' @return A two-by-two-by-k array where k represents the number of subgroups #' (strata). #' @export +#' @examples +#' dat <- data.table::data.table( +#' USUBJID = c("S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8"), +#' TRT = c("Active", "Active", "Active", "Active", +#' "Placebo", "Placebo", "Placebo", "Placebo"), +#' STRATA = c("M", "M", "F", "F", "M", "M", "F", "F") +#' ) +#' dat[, INDEX_ := .I] +#' data.table::setkey(dat, INDEX_) +#' make_two_by_two_by_k_(dat, event_index = c(1L, 3L, 5L, 7L), +#' strata_var = "STRATA", +#' treatment_var = "TRT", treatment_refval = "Placebo", +#' subjectid_var = "USUBJID") make_two_by_two_by_k_ <- function(dat, event_index, diff --git a/R/use_chefStats.R b/R/use_chefStats.R index 4b5a0e0..96c4142 100644 --- a/R/use_chefStats.R +++ b/R/use_chefStats.R @@ -9,7 +9,10 @@ #' #' @return Nothing, run for side-effect (writes file to disk) #' @export -#' +#' @examples +#' \dontrun{ +#' use_chefStats(fn_name = "my_stat_fn", fn_type = "stat_by_strata_by_trt") +#' } use_chefStats <- function(fn_name, fn_type = c( diff --git a/man/OR.Rd b/man/OR.Rd index 584496e..ce3287f 100644 --- a/man/OR.Rd +++ b/man/OR.Rd @@ -42,3 +42,14 @@ Ensures the input to the statistical function is in the proper format, and ensures the output is formatted to the need of the AMNOG workflow. } +\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_) +OR(dat, event_index = c(1L, 2L, 4L), cell_index = dat[["INDEX_"]], + treatment_var = "TRT", treatment_refval = "Placebo", + subjectid_var = "USUBJID") +} diff --git a/man/RD.Rd b/man/RD.Rd index 2be2fac..6c3d4fd 100644 --- a/man/RD.Rd +++ b/man/RD.Rd @@ -45,3 +45,14 @@ Ensures the input to the statistical function is in the proper format, and ensures the output is formatted to the need of the AMNOG workflow. } +\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_) +RD(dat, event_index = c(1L, 2L, 4L), cell_index = dat[["INDEX_"]], + treatment_var = "TRT", treatment_refval = "Placebo", + subjectid_var = "USUBJID") +} diff --git a/man/RR.Rd b/man/RR.Rd index b465cca..08cdbc1 100644 --- a/man/RR.Rd +++ b/man/RR.Rd @@ -42,3 +42,14 @@ Ensures the input to the statistical function is in the proper format, and ensure the output is formatted to the need of the AMNOG workflow. } +\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_) +RR(dat, event_index = c(1L, 2L, 4L), cell_index = dat[["INDEX_"]], + treatment_var = "TRT", treatment_refval = "Placebo", + subjectid_var = "USUBJID") +} diff --git a/man/count_set.Rd b/man/count_set.Rd index 56f32a4..38dc0c3 100644 --- a/man/count_set.Rd +++ b/man/count_set.Rd @@ -33,3 +33,10 @@ function will produce all the described functions. This can be useful to save compute time as inside the chef pipeline there will be fewer iterations. } +\examples{ +dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3", "S4")) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +count_set(dat, event_index = c(1L, 2L), cell_index = dat[["INDEX_"]], + subjectid_var = "USUBJID") +} diff --git a/man/demographics_continuous.Rd b/man/demographics_continuous.Rd index 4cf2cd7..f4cc299 100644 --- a/man/demographics_continuous.Rd +++ b/man/demographics_continuous.Rd @@ -30,3 +30,14 @@ A data.table containing the summary statistics for the given continuous variable \description{ Calculate a set of summary statistics (mean, median, sd, min, max, n_non_missing, n_missing) on a continuous variable for demographics endpoints. } +\examples{ +dat <- data.table::data.table( + USUBJID = c("S1", "S2", "S3", "S4"), + AGE = c(45, 52, 60, 38) +) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +demographics_continuous(dat, event_index = dat[["INDEX_"]], + cell_index = dat[["INDEX_"]], + subjectid_var = "USUBJID", var = "AGE") +} diff --git a/man/demographics_counts.Rd b/man/demographics_counts.Rd index 580cb80..8e569ea 100644 --- a/man/demographics_counts.Rd +++ b/man/demographics_counts.Rd @@ -35,3 +35,15 @@ A data.table containing the summary statistics. \description{ Calculate summary statistics (n_non_missing, n_missing) on a variable for demographics endpoints. } +\examples{ +dat <- data.table::data.table( + USUBJID = c("S1", "S2", "S3", "S4"), + SEX = c("M", "F", "M", NA_character_) +) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +demographics_counts(dat, cell_index = dat[["INDEX_"]], + subjectid_var = "USUBJID", + stratify_by = c("TOTAL_", "SEX"), + strata_var = "SEX") +} diff --git a/man/hedges_g.Rd b/man/hedges_g.Rd index bbb252e..4ad5f4e 100644 --- a/man/hedges_g.Rd +++ b/man/hedges_g.Rd @@ -23,3 +23,11 @@ A list containing Hedges G statistics. \description{ Wrapper to prepare data for Hedges G } +\examples{ +dat <- data.table::data.table( + treatment_val = c("Active", "Active", "Active", "Placebo", "Placebo", "Placebo"), + stat_var = rep(c("N_sub", "mean_value", "sd_value"), 2), + stat_val = c(50, 12.3, 2.1, 50, 10.1, 2.5) +) +hedges_g(dat, reference_val = "Placebo") +} diff --git a/man/make_two_by_two_.Rd b/man/make_two_by_two_.Rd index 1e5f072..b53e4cf 100644 --- a/man/make_two_by_two_.Rd +++ b/man/make_two_by_two_.Rd @@ -48,3 +48,15 @@ criteria of each 2x2 cell. Only observations that have a Treatment value recorded are returned. } +\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_) +make_two_by_two_(dat, event_index = c(1L, 2L, 4L), + cell_index = dat[["INDEX_"]], + treatment_var = "TRT", treatment_refval = "Placebo", + subjectid_var = "USUBJID") +} diff --git a/man/make_two_by_two_by_k_.Rd b/man/make_two_by_two_by_k_.Rd index 8635196..4f6e312 100644 --- a/man/make_two_by_two_by_k_.Rd +++ b/man/make_two_by_two_by_k_.Rd @@ -35,3 +35,17 @@ A two-by-two-by-k array where k represents the number of subgroups Make 2x2xk contingency tables from summarized adam data. This function is NOT generalized } +\examples{ +dat <- data.table::data.table( + USUBJID = c("S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8"), + TRT = c("Active", "Active", "Active", "Active", + "Placebo", "Placebo", "Placebo", "Placebo"), + STRATA = c("M", "M", "F", "F", "M", "M", "F", "F") +) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +make_two_by_two_by_k_(dat, event_index = c(1L, 3L, 5L, 7L), + strata_var = "STRATA", + treatment_var = "TRT", treatment_refval = "Placebo", + subjectid_var = "USUBJID") +} diff --git a/man/mean_value.Rd b/man/mean_value.Rd index 7b031c0..194f3ee 100644 --- a/man/mean_value.Rd +++ b/man/mean_value.Rd @@ -4,8 +4,6 @@ \alias{mean_value} \title{Calculate mean value} \usage{ -mean_value(dat, event_index, cell_index, subjectid_var, var, ...) - mean_value(dat, event_index, cell_index, subjectid_var, var, ...) } \arguments{ @@ -27,10 +25,18 @@ for more information.} \item{...}{Optional parameters.} } \value{ -A data.table containing the percentage of subjects with events by treatment. - A data.table containing the mean value. } \description{ Calculate the mean value of a variable } +\examples{ +dat <- data.table::data.table( + USUBJID = c("S1", "S2", "S3"), + AVAL = c(1.5, 2.5, 3.5) +) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +mean_value(dat, event_index = dat[["INDEX_"]], cell_index = dat[["INDEX_"]], + subjectid_var = "USUBJID", var = "AVAL") +} diff --git a/man/n_event.Rd b/man/n_event.Rd index c629642..def9d2e 100644 --- a/man/n_event.Rd +++ b/man/n_event.Rd @@ -28,3 +28,10 @@ A data.table containing the number of events for the given combination of treatm \description{ Calculate the number of events by treatment and stratum. } +\examples{ +dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3", "S4")) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +n_event(dat, event_index = c(1L, 2L), cell_index = dat[["INDEX_"]], + subjectid_var = "USUBJID") +} diff --git a/man/n_event_.Rd b/man/n_event_.Rd index 0b32a71..a9e255d 100644 --- a/man/n_event_.Rd +++ b/man/n_event_.Rd @@ -19,3 +19,9 @@ an integer value \description{ Building-block: Number of events (multiple events counted multiple times) } +\examples{ +dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3")) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +n_event_(dat, intersect_index = c(1L, 2L)) +} diff --git a/man/n_event_100y.Rd b/man/n_event_100y.Rd index 60c68ac..30f3a46 100644 --- a/man/n_event_100y.Rd +++ b/man/n_event_100y.Rd @@ -40,3 +40,16 @@ A data.table containing the number of events per 100 years of exposure. \description{ Calculate number of events per 100 years of exposure } +\examples{ +dat <- data.table::data.table( + USUBJID = c("S1", "S2", "S3", "S4"), + TRT = c("Active", "Active", "Placebo", "Placebo"), + INTRDURY = c(1.5, 2.0, 0.8, 1.2) +) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +n_event_100y(dat, event_index = c(1L, 2L), + cell_index = dat[TRT == "Active"][["INDEX_"]], + subjectid_var = "USUBJID", + treatment_var = "TRT", treatment_value = "Active") +} diff --git a/man/n_subj.Rd b/man/n_subj.Rd index 6d9bde0..e19e227 100644 --- a/man/n_subj.Rd +++ b/man/n_subj.Rd @@ -24,3 +24,9 @@ A data.table containing the number of subjects for the given combination of trea \description{ Calculate the number of subjects by treatment and stratum. } +\examples{ +dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3")) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +n_subj(dat, cell_index = dat[["INDEX_"]], subjectid_var = "USUBJID") +} diff --git a/man/n_subj_.Rd b/man/n_subj_.Rd index 3f9be64..c589829 100644 --- a/man/n_subj_.Rd +++ b/man/n_subj_.Rd @@ -23,3 +23,12 @@ An integer \description{ Building-block: Number of subjects } +\examples{ +dat <- data.table::data.table( + USUBJID = c("S1", "S2", "S3"), + VALUE = c(1.1, 2.2, 3.3) +) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +n_subj_(dat, cell_index = dat[["INDEX_"]], subjectid_var = "USUBJID") +} diff --git a/man/n_subj_event.Rd b/man/n_subj_event.Rd index a03f0c0..d498c63 100644 --- a/man/n_subj_event.Rd +++ b/man/n_subj_event.Rd @@ -28,3 +28,10 @@ A data.table containing the number of subjects with events for the given combina \description{ Calculate the number of subjects with events by treatment and stratum. } +\examples{ +dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3", "S4")) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +n_subj_event(dat, event_index = c(1L, 2L), cell_index = dat[["INDEX_"]], + subjectid_var = "USUBJID") +} diff --git a/man/n_subj_event_.Rd b/man/n_subj_event_.Rd index 1a69d87..8a487a0 100644 --- a/man/n_subj_event_.Rd +++ b/man/n_subj_event_.Rd @@ -22,3 +22,9 @@ an interger value \description{ Building-block: Number of subjects with at least one event } +\examples{ +dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3")) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +n_subj_event_(dat, intersect_index = c(1L, 2L), subjectid_var = "USUBJID") +} diff --git a/man/obs_time_by_trt.Rd b/man/obs_time_by_trt.Rd index fae7ef5..2ce1ca7 100644 --- a/man/obs_time_by_trt.Rd +++ b/man/obs_time_by_trt.Rd @@ -24,3 +24,12 @@ A data.table containing the observation time by treatment. \description{ Calculate observation time by treatment } +\examples{ +dat <- data.table::data.table( + USUBJID = c("S1", "S2", "S3"), + INTRDURY = c(1.5, 2.0, 0.8) +) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +obs_time_by_trt(dat, cell_index = dat[["INDEX_"]], subjectid_var = "USUBJID") +} diff --git a/man/p_subj_event.Rd b/man/p_subj_event.Rd index c86b8cd..5e0a83f 100644 --- a/man/p_subj_event.Rd +++ b/man/p_subj_event.Rd @@ -28,3 +28,10 @@ A data.table containing the percentage of subjects with events for the given com \description{ Calculate the percentage of subjects with events by treatment and stratum. } +\examples{ +dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3", "S4")) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +p_subj_event(dat, event_index = c(1L, 2L), cell_index = dat[["INDEX_"]], + subjectid_var = "USUBJID") +} diff --git a/man/p_subj_event_.Rd b/man/p_subj_event_.Rd index 7153b2a..9f99b2c 100644 --- a/man/p_subj_event_.Rd +++ b/man/p_subj_event_.Rd @@ -27,3 +27,10 @@ an integer value \description{ Building-block: Proportion of subjects having at least one event } +\examples{ +dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3")) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +p_subj_event_(dat, cell_index = 1:3, intersect_index = c(1L, 2L), + subjectid_var = "USUBJID") +} diff --git a/man/p_subj_event_by_trt.Rd b/man/p_subj_event_by_trt.Rd index f06b52d..bf6dba9 100644 --- a/man/p_subj_event_by_trt.Rd +++ b/man/p_subj_event_by_trt.Rd @@ -40,3 +40,15 @@ A data.table containing the percentage of subjects with events by treatment. \description{ Calculate the percentage of subjects with events by treatment and strata. } +\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_) +p_subj_event_by_trt(dat, event_index = c(1L, 2L), + cell_index = dat[TRT == "Active"][["INDEX_"]], + subjectid_var = "USUBJID", + treatment_var = "TRT", treatment_value = "Active") +} diff --git a/man/p_val.Rd b/man/p_val.Rd index b40973b..37d040a 100644 --- a/man/p_val.Rd +++ b/man/p_val.Rd @@ -52,3 +52,14 @@ Ensures the input to the statistical function is in the proper format, and enruse the output is formated to the need of the AMNOG workflow. } +\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_) +p_val(dat, event_index = c(1L, 2L, 4L), cell_index = dat[["INDEX_"]], + treatment_var = "TRT", treatment_refval = "Placebo", + subjectid_var = "USUBJID") +} diff --git a/man/p_val_interaction.Rd b/man/p_val_interaction.Rd index bd7fd72..f9fe6a4 100644 --- a/man/p_val_interaction.Rd +++ b/man/p_val_interaction.Rd @@ -43,3 +43,16 @@ A data.table containing the statistics for p-value interaction tests. \description{ Wrapper for P-value of interaction tests } +\examples{ +dat <- data.table::data.table( + USUBJID = c("S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8"), + TRT = c("Active", "Active", "Active", "Active", + "Placebo", "Placebo", "Placebo", "Placebo"), + STRATA = c("M", "M", "F", "F", "M", "M", "F", "F") +) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +p_val_interaction(dat, event_index = c(1L, 3L, 5L, 7L), + treatment_var = "TRT", treatment_refval = "Placebo", + subjectid_var = "USUBJID", strata_var = "STRATA") +} diff --git a/man/sd_value.Rd b/man/sd_value.Rd index a0fd5b2..aeaf1f2 100644 --- a/man/sd_value.Rd +++ b/man/sd_value.Rd @@ -30,3 +30,13 @@ A data.table containing the standard deviation. \description{ Standard deviation } +\examples{ +dat <- data.table::data.table( + USUBJID = c("S1", "S2", "S3"), + AVAL = c(1.5, 2.5, 3.5) +) +dat[, INDEX_ := .I] +data.table::setkey(dat, INDEX_) +sd_value(dat, event_index = dat[["INDEX_"]], cell_index = dat[["INDEX_"]], + subjectid_var = "USUBJID", var = "AVAL") +} diff --git a/man/use_chefStats.Rd b/man/use_chefStats.Rd index 6510d33..0392b1c 100644 --- a/man/use_chefStats.Rd +++ b/man/use_chefStats.Rd @@ -27,3 +27,8 @@ Nothing, run for side-effect (writes file to disk) \description{ Make new chefStats functions } +\examples{ +\dontrun{ +use_chefStats(fn_name = "my_stat_fn", fn_type = "stat_by_strata_by_trt") +} +} From 286c46060b8e5f595dd27cf888ad7ac3dcb77fba Mon Sep 17 00:00:00 2001 From: "CINO (Christian Haargaard Olsen)" Date: Fri, 17 Apr 2026 13:46:52 +0200 Subject: [PATCH 5/7] Fix R CMD check NOTEs: add J to globalVariables and use \pkg{} for ramnog - Add "J" to globalVariables() to suppress 'no visible global function definition for J' NOTE in obs_time_by_trt and sd_value - Replace bare {ramnog} with \pkg{ramnog} in 19 Rd files and all corresponding R source files to fix 'Lost braces' checkRd warnings Co-Authored-By: Claude Sonnet 4.6 --- R/building_blocks.R | 4 ++-- R/by_strata_across_trt.R | 8 ++++---- R/by_strata_by_trt.R | 24 ++++++++++++------------ R/globals.R | 3 ++- R/two_by_two_x.R | 2 +- man/OR.Rd | 2 +- man/RD.Rd | 2 +- man/RR.Rd | 2 +- man/count_set.Rd | 2 +- man/demographics_continuous.Rd | 2 +- man/demographics_counts.Rd | 2 +- man/make_two_by_two_.Rd | 2 +- man/mean_value.Rd | 2 +- man/n_event.Rd | 2 +- man/n_event_100y.Rd | 2 +- man/n_subj.Rd | 2 +- man/n_subj_.Rd | 2 +- man/n_subj_event.Rd | 2 +- man/obs_time_by_trt.Rd | 2 +- man/p_subj_event.Rd | 2 +- man/p_subj_event_.Rd | 2 +- man/p_subj_event_by_trt.Rd | 2 +- man/p_val.Rd | 2 +- man/sd_value.Rd | 2 +- 24 files changed, 40 insertions(+), 39 deletions(-) diff --git a/R/building_blocks.R b/R/building_blocks.R index ef025af..908ab04 100644 --- a/R/building_blocks.R +++ b/R/building_blocks.R @@ -2,7 +2,7 @@ #' #' @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} for more +#' analyzed. See the "Endpoint Events" vignette in \pkg{ramnog} for more #' information. #' @param subjectid_var character. Name of the subject identifier variable in #' the data (default is "USUBJID"). @@ -72,7 +72,7 @@ n_subj_event_ <- function(dat, intersect_index, subjectid_var) { #' @param dat data.table. The analysis data set. #' @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} for more +#' analyzed. See the "Endpoint Events" vignette in \pkg{ramnog} for more #' information. #' @param intersect_index A vector of intergers referencing the rows of `dat` #' that match both (1) the population to be analyzed and (2) the defenition of diff --git a/R/by_strata_across_trt.R b/R/by_strata_across_trt.R index b6f194e..e25e2ac 100644 --- a/R/by_strata_across_trt.R +++ b/R/by_strata_across_trt.R @@ -9,7 +9,7 @@ #' `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 the data. #' @param treatment_refval character. The reference value of the treatment variable in the data. @@ -76,7 +76,7 @@ RR <- function(dat, #' `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 the data. #' @param treatment_refval character. The reference value of the treatment variable in the data. @@ -144,7 +144,7 @@ OR <- function(dat, #' `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 the data. #' @param treatment_refval character. The reference value of the treatment variable in the data. @@ -214,7 +214,7 @@ RD <- function(dat, #' `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 safe_mode Boolean determing if the function should fail when given #' input that cannot be calculated (`safe_mode = TRUE`), or if it should silently return a `NA` value (default). diff --git a/R/by_strata_by_trt.R b/R/by_strata_by_trt.R index ba93e71..327a2ce 100644 --- a/R/by_strata_by_trt.R +++ b/R/by_strata_by_trt.R @@ -5,7 +5,7 @@ #' @param dat data.table. The analysis data set. #' @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 subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). #' @param ... Optional parameters. @@ -47,7 +47,7 @@ n_subj <- function(dat, #' `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 subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). #' @param ... Optional parameters. @@ -91,7 +91,7 @@ n_event <- #' `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 subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). #' @param ... Optional parameters. @@ -137,7 +137,7 @@ n_subj_event <- #' `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 subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). #' @param ... Optional parameters. @@ -193,7 +193,7 @@ p_subj_event <- #' `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 subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). #' @param ... Optional parameters. @@ -253,7 +253,7 @@ count_set <- function(dat, #' `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 subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). #' @param var character. Name of the variable in the analysis data that is subject to the statistics. @@ -312,7 +312,7 @@ demographics_continuous <- function(dat, #' @param dat data.table. The analysis data set. #' @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 subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). #' @param stratify_by character vector. Set of variables in the analysis data to stratify by. @@ -395,7 +395,7 @@ total_missing_counts <- function(dat_cell, stratify_by) { #' `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 subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). #' @param treatment_var character. Name of the treatment variable in the data. @@ -457,7 +457,7 @@ p_subj_event_by_trt <- #' @param dat data.table. The analysis data set. #' @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 subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). #' @param ... Optional parameters. @@ -500,7 +500,7 @@ obs_time_by_trt <- function(dat, #' `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 subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). #' @param treatment_var character. Name of the treatment variable in the data. @@ -557,7 +557,7 @@ n_event_100y <- function(dat, #' `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 subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). #' @param var character. Name of the variable in the analysis data that is subject to the statistics. @@ -604,7 +604,7 @@ mean_value <- function(dat, #' `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 subjectid_var character. Name of the subject identifier variable in the data (default is "USUBJID"). #' @param var Character. Name of the variable in the analysis data that is subject to the statistics. diff --git a/R/globals.R b/R/globals.R index 4fff8da..95ea46b 100644 --- a/R/globals.R +++ b/R/globals.R @@ -12,6 +12,7 @@ utils::globalVariables( "stat_var", "value", "N_sub", - "N_no_event" + "N_no_event", + "J" ) ) diff --git a/R/two_by_two_x.R b/R/two_by_two_x.R index 995863d..5b32466 100644 --- a/R/two_by_two_x.R +++ b/R/two_by_two_x.R @@ -18,7 +18,7 @@ #' `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`. diff --git a/man/OR.Rd b/man/OR.Rd index ce3287f..7bb3702 100644 --- a/man/OR.Rd +++ b/man/OR.Rd @@ -23,7 +23,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 the data.} diff --git a/man/RD.Rd b/man/RD.Rd index 6c3d4fd..22067bc 100644 --- a/man/RD.Rd +++ b/man/RD.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 the data.} diff --git a/man/RR.Rd b/man/RR.Rd index 08cdbc1..c49013e 100644 --- a/man/RR.Rd +++ b/man/RR.Rd @@ -23,7 +23,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 the data.} diff --git a/man/count_set.Rd b/man/count_set.Rd index 38dc0c3..892740b 100644 --- a/man/count_set.Rd +++ b/man/count_set.Rd @@ -16,7 +16,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{subjectid_var}{character. Name of the subject identifier variable in the data (default is "USUBJID").} diff --git a/man/demographics_continuous.Rd b/man/demographics_continuous.Rd index f4cc299..6929257 100644 --- a/man/demographics_continuous.Rd +++ b/man/demographics_continuous.Rd @@ -15,7 +15,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{subjectid_var}{character. Name of the subject identifier variable in the data (default is "USUBJID").} diff --git a/man/demographics_counts.Rd b/man/demographics_counts.Rd index 8e569ea..da1853b 100644 --- a/man/demographics_counts.Rd +++ b/man/demographics_counts.Rd @@ -18,7 +18,7 @@ demographics_counts( \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{subjectid_var}{character. Name of the subject identifier variable in the data (default is "USUBJID").} diff --git a/man/make_two_by_two_.Rd b/man/make_two_by_two_.Rd index b53e4cf..f5d12c0 100644 --- a/man/make_two_by_two_.Rd +++ b/man/make_two_by_two_.Rd @@ -22,7 +22,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}.} diff --git a/man/mean_value.Rd b/man/mean_value.Rd index 194f3ee..698e707 100644 --- a/man/mean_value.Rd +++ b/man/mean_value.Rd @@ -15,7 +15,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{subjectid_var}{character. Name of the subject identifier variable in the data (default is "USUBJID").} diff --git a/man/n_event.Rd b/man/n_event.Rd index def9d2e..ad76e35 100644 --- a/man/n_event.Rd +++ b/man/n_event.Rd @@ -15,7 +15,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{subjectid_var}{character. Name of the subject identifier variable in the data (default is "USUBJID").} diff --git a/man/n_event_100y.Rd b/man/n_event_100y.Rd index 30f3a46..07c9248 100644 --- a/man/n_event_100y.Rd +++ b/man/n_event_100y.Rd @@ -23,7 +23,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{subjectid_var}{character. Name of the subject identifier variable in the data (default is "USUBJID").} diff --git a/man/n_subj.Rd b/man/n_subj.Rd index e19e227..59828a9 100644 --- a/man/n_subj.Rd +++ b/man/n_subj.Rd @@ -11,7 +11,7 @@ n_subj(dat, cell_index, subjectid_var, ...) \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{subjectid_var}{character. Name of the subject identifier variable in the data (default is "USUBJID").} diff --git a/man/n_subj_.Rd b/man/n_subj_.Rd index c589829..405770a 100644 --- a/man/n_subj_.Rd +++ b/man/n_subj_.Rd @@ -11,7 +11,7 @@ n_subj_(dat, cell_index, subjectid_var) \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} for more +analyzed. See the "Endpoint Events" vignette in \pkg{ramnog} for more information.} \item{subjectid_var}{character. Name of the subject identifier variable in diff --git a/man/n_subj_event.Rd b/man/n_subj_event.Rd index d498c63..8750e39 100644 --- a/man/n_subj_event.Rd +++ b/man/n_subj_event.Rd @@ -15,7 +15,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{subjectid_var}{character. Name of the subject identifier variable in the data (default is "USUBJID").} diff --git a/man/obs_time_by_trt.Rd b/man/obs_time_by_trt.Rd index 2ce1ca7..28138e6 100644 --- a/man/obs_time_by_trt.Rd +++ b/man/obs_time_by_trt.Rd @@ -11,7 +11,7 @@ obs_time_by_trt(dat, cell_index, subjectid_var, ...) \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{subjectid_var}{character. Name of the subject identifier variable in the data (default is "USUBJID").} diff --git a/man/p_subj_event.Rd b/man/p_subj_event.Rd index 5e0a83f..0dd9bbd 100644 --- a/man/p_subj_event.Rd +++ b/man/p_subj_event.Rd @@ -15,7 +15,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{subjectid_var}{character. Name of the subject identifier variable in the data (default is "USUBJID").} diff --git a/man/p_subj_event_.Rd b/man/p_subj_event_.Rd index 9f99b2c..e007587 100644 --- a/man/p_subj_event_.Rd +++ b/man/p_subj_event_.Rd @@ -11,7 +11,7 @@ p_subj_event_(dat, cell_index, intersect_index, subjectid_var) \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} for more +analyzed. See the "Endpoint Events" vignette in \pkg{ramnog} for more information.} \item{intersect_index}{A vector of intergers referencing the rows of \code{dat} diff --git a/man/p_subj_event_by_trt.Rd b/man/p_subj_event_by_trt.Rd index bf6dba9..2132f48 100644 --- a/man/p_subj_event_by_trt.Rd +++ b/man/p_subj_event_by_trt.Rd @@ -23,7 +23,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{subjectid_var}{character. Name of the subject identifier variable in the data (default is "USUBJID").} diff --git a/man/p_val.Rd b/man/p_val.Rd index 37d040a..8430b5e 100644 --- a/man/p_val.Rd +++ b/man/p_val.Rd @@ -26,7 +26,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 the data.} diff --git a/man/sd_value.Rd b/man/sd_value.Rd index aeaf1f2..e7f7606 100644 --- a/man/sd_value.Rd +++ b/man/sd_value.Rd @@ -15,7 +15,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{subjectid_var}{character. Name of the subject identifier variable in the data (default is "USUBJID").} From 9f69bee2f190c082a349abfdf45b1009c2b1f5e0 Mon Sep 17 00:00:00 2001 From: "CINO (Christian Haargaard Olsen)" Date: Fri, 17 Apr 2026 13:59:56 +0200 Subject: [PATCH 6/7] Fix URL redirects in README.md: add trailing slashes to GitHub Pages URLs Co-Authored-By: Claude Sonnet 4.6 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1298bbb..c1d5108 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ The {chefStats} package aims to provide a library of fast, validated methods for use in AMNOG analysis created by the chef package. As the functions found in chefStats are designed to be used with -[chef](https://hta-pharma.github.io/chef) in the context of the -[ramnog](https://hta-pharma.github.io/ramnog) framework, it may be +[chef](https://hta-pharma.github.io/chef/) in the context of the +[ramnog](https://hta-pharma.github.io/ramnog/) framework, it may be unwieldy to use these functions independently. # Installation @@ -33,5 +33,5 @@ documentation](https://hta-pharma.github.io/ramnog/articles/dev_contribute). These site focuses on the functions of chefStats. For more context on how these functions should be utilized to produce an AMNOG-like -analysis, please see the [ramnog](https://hta-pharma.github.io/ramnog) +analysis, please see the [ramnog](https://hta-pharma.github.io/ramnog/) documentation. From 7c8bb999ccccdaf8913b6669b7d2a2ae9fa3bf15 Mon Sep 17 00:00:00 2001 From: "CINO (Christian Haargaard Olsen)" Date: Wed, 27 May 2026 22:51:50 +0200 Subject: [PATCH 7/7] Add Remotes: chef and tools/strip-remotes.R helper for CRAN submission Adds Remotes: hta-pharma/chef@feature/CRAN_submission so GitHub Actions can resolve {chef} from GitHub during CI (it is not yet on CRAN). CRAN forbids Remotes: in submitted tarballs, so tools/strip-remotes.R removes the field before R CMD build. The helper restores DESCRIPTION afterwards when invoked with --build, leaving the working tree unchanged. Both tools/ and cran-plan.md are ignored at build time. Co-Authored-By: Claude Opus 4.7 --- .Rbuildignore | 2 ++ DESCRIPTION | 2 ++ tools/strip-remotes.R | 68 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tools/strip-remotes.R diff --git a/.Rbuildignore b/.Rbuildignore index dcba0eb..ca6c541 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -23,3 +23,5 @@ setImgSrc.js \.github RELEASE_BODY\.txt ^\.github$ +^cran-plan\.md$ +^tools$ diff --git a/DESCRIPTION b/DESCRIPTION index 8f5db2c..019f24d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,6 +32,8 @@ BugReports: https://github.com/hta-pharma/chefStats/issues Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 +Remotes: + hta-pharma/chef@feature/CRAN_submission Suggests: covr, pkgdown, 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.") +}