View source: R/check_package_parameters.R
check_package_parameters | R Documentation |
This function checks the structure and content of a given package 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 and prints error messages if critical errors are found.
check_package_parameters(
dt,
pack_atc = NULL,
pack_id = NULL,
pack_ddd_low = NULL,
pack_ddd_usual = NULL,
pack_dur_min = NULL,
pack_dur_usual = NULL,
pack_dur_max = NULL,
print_all = FALSE,
return_data = FALSE
)
dt |
data.frame or data.table containing the package parameters to validate. |
pack_atc |
Character. Name of the column containing the Anatomical Therapeutic Chemical (ATC) Classification code. |
pack_id |
Character. Name of the column containing the package identifier (e.g., vnr code). |
pack_ddd_low |
Character. Name of the column with the minimum daily DDD value. |
pack_ddd_usual |
Character. Name of the column with the usual daily DDD value. |
pack_dur_min |
Character. Name of the column with the minimum package duration (in days). |
pack_dur_usual |
Character. Name of the column with the usual package duration (in days). |
pack_dur_max |
Character. Name of the column with the maximum package duration (in days). |
print_all |
Logical. If TRUE, all warnings are printed. If FALSE, only the first 5 problematic rows are printed. |
return_data |
Logical. If TRUE and no errors are detected, returns a data.table with the validated columns and proper types. If FALSE, only a message is printed. |
The following checks are performed:
Existence and naming of required columns
Uniqueness of package identifiers (no duplicates)
Validity of ATC codes (no missing or invalid values, correct type)
Validity of package IDs (should be numeric, no missing values)
Validity of DDD and duration values (no negative or missing values, logical value ranges)
Correct order of minimum, usual, and maximum durations
Correct order of minimum and usual DDD values
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 <- c("N05AA01", rep("N05AH03", 3), "N05AX13")
vnr <- c(141473, 80307, 145698, 457780 , 412581)
lower_ddd = c(0.167, 0.500, 0.500, 0.375, 0.714)
usual_ddd <- c(0.33, 1.00, 1.00, 0.75, 1.00)
minimum_duration <- c(33, 9.3, 9.3, 33.3, 14)
usual_duration <- c(100, 28, 28, 100, 30)
maximum_duration <- c(200, 56, 56, 200, 42)
df_pack_params <- data.frame(ATC, vnr, lower_ddd, usual_ddd,
minimum_duration, usual_duration, maximum_duration)
package_parameters <- check_package_parameters(
dt = df_pack_params,
pack_atc = "ATC",
pack_id = "vnr",
pack_ddd_low = "lower_ddd",
pack_ddd_usual = "usual_ddd",
pack_dur_min = "minimum_duration",
pack_dur_usual = "usual_duration",
pack_dur_max = "maximum_duration",
return_data = TRUE
)
package_parameters
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.