View source: R/check_atc_parameters.R
check_atc_parameters | R Documentation |
Anatomical Therapeutic Chemical (ATC) Classification System parameters are used to define the classification of drugs and their daily defined doses (DDD).
This function checks the structure and content of a given ATC parameter file (data.frame or data.table) for use in pre2dup
workflows.
The validation covers required columns, uniqueness, data types, value ranges, and logical consistency.
The function stops execution if critical errors are found.
check_atc_parameters(
dt,
atc_class = NULL,
atc_ddd_low = NULL,
atc_ddd_usual = NULL,
atc_dur_min = NULL,
atc_dur_max = NULL,
print_all = FALSE,
return_data = FALSE
)
dt |
data.frame or data.table containing the ATC parameters to validate. |
atc_class |
Character. Name of the column containing the ATC class or code. |
atc_ddd_low |
Character. Name of the column with the minimum daily DDD value. |
atc_ddd_usual |
Character. Name of the column with the usual daily DDD value. |
atc_dur_min |
Character. Name of the column with the minimum duration (in days). |
atc_dur_max |
Character. Name of the column with the maximum duration (in days). |
print_all |
Logical. If TRUE, all warnings are printed. |
return_data |
Logical. If TRUE, the function returns the validated data. If FALSE, only a message is printed. |
The following checks are performed:
Existence and naming of required columns
Uniqueness of ATC class values (no duplicates)
Validity of ATC codes (no missing or invalid values, correct type)
Validity of DDD and duration values (no negative or missing values, logical value ranges)
Correct order of minimum and maximum values (duration and DDD)
If any errors are found, the function stops execution and prints all error messages.
If return_data = TRUE
, returns a data.table containing only the validated columns, with converted types.
If errors are detected, the function stops and prints error messages.
atc_data <- data.frame(
atc_class = c("A01", "A02", "A03"),
atc_ddd_low = c(0.1, 0.2, 0.3),
atc_ddd_usual = c(1, 2, 3),
atc_dur_min = c(10, 28, 35),
atc_dur_max = c(40, 56, 100)
)
# Validate and return the data if all checks pass
check_atc_parameters(
dt = atc_data,
atc_class = "atc_class",
atc_ddd_low = "atc_ddd_low",
atc_ddd_usual = "atc_ddd_usual",
atc_dur_min = "atc_dur_min",
atc_dur_max = "atc_dur_max",
print_all = TRUE,
return_data = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.