Number of occurrences of a specific drug class based on given conditions
Source:R/medications.R
is_taking_drug_class.RdThis function calculates the number of occurrences of a specific drug class in a data frame. The calculation is based on custom conditions specified by the user.
Usage
is_taking_drug_class(
df,
class_var_name,
med_vars,
last_taken_vars,
class_condition_fun,
log_level = "INFO",
overwrite = FALSE
)Arguments
- df
data.frame The data frame containing medication and last taken information.
- class_var_name
character The name of the new variable representing the drug class.
- med_vars
character A character vector containing the names of medication variables in the data frame.
- last_taken_vars
character A character vector containing the names of last taken variables in the data frame.
- class_condition_fun
function A custom condition function that determines whether a medication belongs to the drug class. The function should accept two arguments: med_code (character) and last_taken (numeric). It should return an integer, 1 if the medication belongs to the class, 0 otherwise.
- log_level
character The log level for logging messages (default is "INFO").
- overwrite
logical Logical value indicating whether to overwrite the 'class_var_name' if it already exists in the data frame (default is FALSE).
Value
data.frame The input data frame 'df' with an additional column representing the drug class.