r Heading

# Name of subfolder: pktablesection

if(FromCalcPKRatios){
   MyFiles <- str_split_1(unique(MyPKResults[[i]]$File), " / ")
} else {
   MyFiles <- unique(MyPKResults[[i]]$File)
}

if("logical" %in% class(existing_exp_details)){
   # This is when existing_exp_details is NA.
   Deets <- data.frame(Inhibitor1 = "UNKNOWN INHIBITOR", 
                       File = MyFiles)
} else {
   Deets <- existing_exp_details$MainDetails %>% filter(File %in% MyFiles)
}

MyPerpetrator <- determine_myperpetrator(Deets = Deets, 
                                         prettify_compound_names = TRUE)

if(FromCalcPKRatios){
   IndivAnnotations <- 
      list("table_heading" = 
              paste0(
                 "***Table XXX.*** *Simulated ", MeanType, " mean ", 
                 unique(MyPKResults[[i]]$Tissue),  " PK parameters for the file pair ", 
                 str_comma(MyFiles), "*"), 

           "table_caption" = 
              paste0("*Simulated values listed are the ", MeanType, 
                     " means. CV: coefficient of variation; CI: confidence interval. Source simulated data: ", 
                     str_comma(MyFiles), "*"))

} else {

   DosesIncluded <- c("Dose1" = any(str_detect(PKpulled[[i]]$PKpulled, "_dose1|^Dose 1")),
                      "Last" = any(str_detect(PKpulled[[i]]$PKpulled, "_last|^Last dose")))
   DosesIncluded <- str_c(names(DosesIncluded)[DosesIncluded], collapse = " ")

   IndivAnnotations <- make_table_annotations(
      MyPKResults = MyPKResults[[i]] %>% purrr::discard(~all(is.na(.))), 
      MyFile = unique(MyPKResults[[i]]$File), 
      MyCompoundID = unique(MyPKResults[[i]]$CompoundID), 
      prettify_compound_names = prettify_compound_names,
      existing_exp_details = switch(as.character("logical" %in% class(existing_exp_details)), 
                                    "TRUE" = data.frame(), 
                                    "FALSE" = Deets), 
      mean_type = mean_type, 
      DosesIncluded = case_match(DosesIncluded, 
                                 "Dose1 User" ~ "Dose1 Last", 
                                 "Last User" ~ "Last", 
                                 .default = DosesIncluded), 
      tissue = unique(MyPKResults[[i]]$Tissue))

   IndivAnnotations[["table_heading"]] <- 
      paste0("***Table XXX.*** *", 
             IndivAnnotations[["table_heading"]], "*")

   IndivAnnotations[["table_caption"]] <- 
      paste0("*", IndivAnnotations[["table_caption"]], "*")

}

r IndivAnnotations[["table_heading"]]

include_dose_num_i <- check_include_dose_num(
   PK = MyPKResults[[i]] %>% purrr::discard(~all(is.na(.))), 
   include_dose_num = include_dose_num)

if(include_dose_num_i == FALSE){
   names(MyPKResults[[i]]) <- sub("Dose 1 |Last dose |_dose1|_last", "",
                                  names(MyPKResults[[i]]))
}

TempTable <- MyPKResults[[i]] %>% ungroup() %>% 
   purrr::discard(~all(is.na(.))) %>% 
   select(-any_of(c("CompoundID", "Tissue", "File", "Compound")))
names(TempTable) <- sub("perpetrator", MyPerpetrator, names(TempTable))

formatTable_Simcyp(TempTable,
                   merge_shaded_cells = merge_shaded_cells,
                   perpetrator_name = MyPerpetrator, 
                   fontsize = fontsize,
                   prettify_columns = prettify_columns, 
                   add_header_for_DDI = add_header_for_DDI, 
                   highlight_so_cutoffs = highlight_so_cutoffs, 
                   highlight_so_colors = highlight_so_colors)

r IndivAnnotations[["table_caption"]]



shirewoman2/Consultancy documentation built on Feb. 18, 2025, 10 p.m.