Skip to content

Commit

Permalink
Update the code to consider the differnt arms.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbranca committed Jul 30, 2024
1 parent 8b9703d commit e5e0d86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions R/asr_dataprep.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ asr_dataprep <- function(data
names(data)[names(data) == var_trt] <- "trt"
if(tx_var){
names(data)[names(data) == var_tx] <- "intervention"
}else{
data <- data[,!names(data) %in% "intervention"]
}

## relevant variables exist
Expand Down
20 changes: 12 additions & 8 deletions R/asr_safety_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm

trial_type <- match.arg(trial_type, c("imp", "medical device", "other","trp"))

## display unique values in the trt variable
check <- unique(data$trt)
if(!all(check %in% names(n_per_arm))) warning("The treatment groups are not present in the treatment variable in the data set.")
## check whether the intervention variable has been defined
if("intervention" %in% names(data)){
check <- unique(data$intervention)

## Check whether the treatment are defined correctly in the trt variable
if(all(!is.na(n_per_arm)))
if(!all(check %in% names(n_per_arm))) stop("The treatment groups in the data do not match those in 'n_par_arm'. \n",
"Please define the names of the treatment groups in the 'var_tx' variable or set 'n_par_arm' to NA.")
}
if(trial_type == "imp"){
# FOR IMP TRIALS

Expand Down Expand Up @@ -85,8 +90,7 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
'Suspected Unexpected Serious Adverse Reactions, SUSARs (only for IMPs)'),
stringsAsFactors = FALSE)

if(all(!is.na(n_per_arm)))
if(!all(check %in% names(n_per_arm))){
if("intervention" %in% names(data)){
### define the values for the two interventional groups
grp <- names(n_per_arm)

Expand Down Expand Up @@ -186,7 +190,7 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
'Safety and protective measures taken in Switzerland and abroad.'),
stringsAsFactors = FALSE)

if(all(!is.na(n_per_arm))){
if("intervention" %in% names(data)){

### define the values for the two interventional groups
grp <- names(n_per_arm)
Expand Down Expand Up @@ -255,7 +259,7 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
'Other SAEs where a causality to the intervention cannot be excluded'),
stringsAsFactors = FALSE)

if(all(!is.na(n_per_arm))){
if("intervention" %in% names(data)){

### define the values for the two interventional groups
grp <- names(n_per_arm)
Expand Down Expand Up @@ -328,7 +332,7 @@ asr_safety_summary <- function(data, period_data, trial_type, n_pat_e, n_per_arm
'Serious Adverse Drug Reactions, SADRs', 'Suspected Unexpected Serious Adverse Reactions, SUSARs'),
stringsAsFactors = FALSE)

if(all(!is.na(n_per_arm))){
if("intervention" %in% names(data)){

grp <- names(n_per_arm)

Expand Down

0 comments on commit e5e0d86

Please sign in to comment.