From 49ab6e4ef53857b6177dad22a357b9dc0326722a Mon Sep 17 00:00:00 2001 From: Danny Colombara Date: Fri, 16 May 2025 15:50:07 -0700 Subject: [PATCH 1/2] validation of years in ph.instructions vs ph.data - now gives a warning and drops rows outside of the available range --- R/chi_calc.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/R/chi_calc.R b/R/chi_calc.R index 0d06d75..d516ef2 100644 --- a/R/chi_calc.R +++ b/R/chi_calc.R @@ -80,6 +80,19 @@ chi_calc <- function(ph.data = NULL, if (nrow(ph.instructions) == 0) stop("\n\U1F6D1 ph.instructions is empty") if (!is.data.table(ph.instructions)) setDT(ph.instructions) + # Validate year range in ph.instructions + if (nrow(ph.instructions[end > max(ph.data[['chi_year']], na.rm = T), ]) > 0){ + warning("\u26A0\ufe0f There are rows in ph.instructions where the end year is > the maximum chi_year in ph.data.\n", + "These rows have been dropped from your instructions.", immediate. = TRUE) + ph.instructions <- ph.instructions[!(end > max(ph.data[['chi_year']], na.rm = T)),] + } + + if (nrow(ph.instructions[start < min(ph.data[['chi_year']], na.rm = T), ]) > 0){ + warning("\u26A0\ufe0f There are rows in ph.instructions where the start year is < the minimum chi_year in ph.data.\n", + "These rows have been dropped from your instructions.", immediate. = TRUE) + ph.instructions <- ph.instructions[!(start < min(ph.data[['chi_year']], na.rm = T)),] + } + # Validate ci parameter if (!is.numeric(ci)) stop("\n\U1F6D1 ci must be numeric") if (ci <= 0 || ci >= 1) stop("\n\U1F6D1 ci must be between 0 and 1") From c65979a6c799df6844c2737627737cac5fe01013 Mon Sep 17 00:00:00 2001 From: Danny Colombara Date: Fri, 16 May 2025 16:04:06 -0700 Subject: [PATCH 2/2] address issues from devtools::check() - added qs to imports - changed .() to list() in chi_get_proper_pop() --- DESCRIPTION | 1 + R/chi_get_proper_pop.R | 4 ++-- man/chi_get_proper_pop.Rd | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 556ff91..141ffe5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,6 +27,7 @@ Imports: glue (>= 1.6.1), odbc (>= 1.2.2), progressr, + qs, rads (>= 1.3.4), rads.data, stats, diff --git a/R/chi_get_proper_pop.R b/R/chi_get_proper_pop.R index d521204..ddbfd08 100644 --- a/R/chi_get_proper_pop.R +++ b/R/chi_get_proper_pop.R @@ -187,8 +187,8 @@ chi_get_proper_pop <- function(pop.template = NULL, # Use a non-equi join to match all_population_data rows with pop.template rows # based on batched_id and proper year range population_subsets <- all_population_data[ - pop.template[, .(batched_id, start, stop, row_index)], - on = .(batched_id == batched_id, year >= start, year <= stop), + pop.template[, list(batched_id, start, stop, row_index)], + on = list(batched_id == batched_id, year >= start, year <= stop), nomatch = 0 # Drop rows that don't match ] diff --git a/man/chi_get_proper_pop.Rd b/man/chi_get_proper_pop.Rd index 53e6432..91322f3 100644 --- a/man/chi_get_proper_pop.Rd +++ b/man/chi_get_proper_pop.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/chi_get_proper_pop.r +% Please edit documentation in R/chi_get_proper_pop.R \name{chi_get_proper_pop} \alias{chi_get_proper_pop} \title{Get Population Denominators for CHI Analysis}