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_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") 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}