Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Imports:
glue (>= 1.6.1),
odbc (>= 1.2.2),
progressr,
qs,
rads (>= 1.3.4),
rads.data,
stats,
Expand Down
13 changes: 13 additions & 0 deletions R/chi_calc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions R/chi_get_proper_pop.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

Expand Down
2 changes: 1 addition & 1 deletion man/chi_get_proper_pop.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.