# 1) Find all .R files in this directory
script_files <- list.files(
  path       = ".", 
  pattern    = "\\.R$", 
  full.names = TRUE
)

# 2) Exclude this driver script itself
script_files <- script_files[basename(script_files) != "run_all.R"]

# 3) Pull out Consolidation.R so we can append it last
is_cons     <- basename(script_files) == "Consolidation.R"
cons_file   <- script_files[is_cons]
other_files <- script_files[!is_cons]

# 4) Sort the “other” scripts, then append Consolidation.R
other_files <- sort(other_files)
script_files <- c(other_files, cons_file)

# 5) Source each one in turn
invisible(lapply(script_files, function(f) {
  message("=== Sourcing ", basename(f), " ===")
  source(f)
}))

message("All done.")
