Author
Affiliation

Vagish Hemmige

Montefiore Medical Center/ Albert Einstein College of Medicine

Table 1 and Table 2: Generating Manuscript-Ready Tables

This section formats the aggregated results into publication-ready tables using the gt package.

Earlier steps produced:

  • Results_HIV_df — coverage results for people living with HIV (PLWH)
  • Results_nonHIV_df — coverage results for people without HIV

Here, those summary data frames are transformed into formatted tables and exported for manuscript use.


Source code

The full R script is available at:

This R script file is itself reliant on the following helper files:


What This Section Does

For each organ:

  1. Constructs descriptive row labels (e.g., “Active kidney center, 60 min radius”).
  2. Converts the results data frame into a formatted gt table.
  3. Saves the tables as:
    • .docx (for manuscript editing)
    • .png (for quick sharing or embedding)
  4. Caches the final gt objects as .rds files for reuse in Quarto.

Step 1: Define Output File Paths

For each organ, file paths are dynamically generated for:

  • Table 1 (PLWH results)
  • Table 2 (Non-HIV population results)

Each table is saved in both:

  • Word format (.docx)
  • Image format (.png)

Existing .docx files are removed first to avoid overwrite conflicts.


Step 2: Create Descriptive Row Labels

The script builds a lookup table (table_factor_values) that:

  • Combines center type (active, HIV, HOPE)
  • Combines distance definitions (e.g., 50mile, 60min)
  • Converts internal codes into human-readable labels

Examples:

  • active 60min → “Active kidney center 60 min radius”
  • HIV 50mile → “Active HIV R+ kidney center 50 mile radius”

This ensures consistent, manuscript-friendly labeling.


Step 3: Convert Results to gt Tables

The helper function convert_resultsdf_to_table():

  • Orders rows consistently
  • Formats percentages
  • Applies table titles
  • Structures the output by year

Two tables are created per organ:

  • Table 1: Access to transplant in PLWH
  • Table 2: Access to transplant in people without HIV

Step 4: Export and Cache

Each table is:

  • Saved as .docx (for manuscript submission workflows)
  • Saved as .png (for presentations or embedding)
  • Stored as an .rds object in the cache/ directory

Caching the gt objects allows Quarto pages to load the formatted tables directly without regenerating them.


Why This Matters

This step translates analytic outputs into:

  • Clean, interpretable manuscript tables
  • Reproducible formatted results
  • Files ready for journal submission

It represents the final transformation from geographic modeling to publication-ready evidence.

Click to show/hide R Code
#Tables


# Initialize lists of gt objects
Results_HIV_gt<-list()
Results_nonHIV_gt<-list()

#Create tables as docx and PNG

for (organ_loop in organ_list)
{
  
  #Initialize file_path
  file_path<-list()
  file_path[["Table 1"]][[".docx"]]<-paste0("tables/", organ_loop,"/",organ_loop, " analysis results Table 1.docx")
  file_path[["Table 2"]][[".docx"]]<-paste0("tables/", organ_loop,"/",organ_loop, " analysis results Table 2.docx")
  file_path[["Table 1"]][[".png"]]<-paste0("tables/", organ_loop,"/",organ_loop, " analysis results Table 1.png")
  file_path[["Table 2"]][[".png"]]<-paste0("tables/", organ_loop,"/",organ_loop, " analysis results Table 2.png")
  
  #Define table with labels based on values in distance_list and types of outcomes
  
  table_factor_values<-expand.grid(
    Type = c("active", "HIV", "HOPE"),
    Distance = distance_list,
    stringsAsFactors = FALSE)%>%
    mutate(value=paste(Type, Distance))%>%
    mutate(
      label = paste(
        recode(Type,
               active = paste("Active", organ_loop, "center"),
               HIV    = paste("Active HIV R+", organ_loop, "center"),
               HOPE   = paste("Active HOPE D+", organ_loop, "center")
        ),
        case_when(
          stringr::str_detect(Distance, "mile$") ~ 
            stringr::str_replace(Distance, "mile$", " mile radius"),
          stringr::str_detect(Distance, "min$")  ~ 
            stringr::str_replace(Distance, "min$", " min radius"),
          TRUE ~ Distance
        )
      )
    )
  
  #Remove .docx files if they exist
  if (file.exists(file_path[["Table 1"]][[".docx"]])) {
    file.remove(file_path[["Table 1"]][[".docx"]])
  }
  
  if (file.exists(file_path[["Table 2"]][[".docx"]])) {
    file.remove(file_path[["Table 2"]][[".docx"]])
  }
  
  #Create tables and save results as .docx and PNG
  Results_HIV_gt[[organ_loop]]<-Results_HIV_df[[organ_loop]]%>%
    convert_resultsdf_to_table(year_list_fn=year_list,
                               row_values = table_factor_values$value,
                               row_labels = table_factor_values$label,
                               table_title= "Access to transplant in PLWH")
  gtsave(Results_HIV_gt[[organ_loop]], file_path[["Table 1"]][[".docx"]])
  gtsave(Results_HIV_gt[[organ_loop]], file_path[["Table 1"]][[".png"]])
  
  Results_nonHIV_gt[[organ_loop]]<-Results_nonHIV_df[[organ_loop]]%>%
    convert_resultsdf_to_table(year_list_fn=year_list,
                               row_values = table_factor_values$value,
                               row_labels = table_factor_values$label,
                               table_title= "Access to transplant in people without HIV")
  gtsave(Results_nonHIV_gt[[organ_loop]], file_path[["Table 2"]][[".docx"]])
  gtsave(Results_nonHIV_gt[[organ_loop]], file_path[["Table 2"]][[".png"]])
  
  
  
}

#Save table objects as .RDS so they can be accessed by Quarto
saveRDS(Results_HIV_gt, "cache/Results_HIV_gt.rds")
saveRDS(Results_nonHIV_gt, "cache/Results_nonHIV_gt.rds")

Other portions of the analysis

  • Setup: Defines global paths, data sources, cohort inclusion criteria, and analysis-wide constants.
  • Functions: Reusable helper functions for cohort construction, matching, costing, and modeling.
  • Figures:Visualizations of costs, risks, and model-based estimates.
  • About: methods, assumptions, and disclosures