This function re-orders the prefices in names of scripts– originally intended to re-order the numbering of scripts developed in the R-Bioconductor-powered data science team's organization style, where script names begin with 01, 02, etc. References to script names within the shell or R scripts are also updated, along with the names of log files they produce.

renumber(base_dir, pre_before, pre_after)

Arguments

base_dir

A character(1) path to a directory containing the scripts to re-order.

pre_before

A character() vector of prefices to replace among scripts in base_dir.

pre_after

A character() vector of replacement prefices among scripts in base_dir.

Author

Nicholas J. Eagles

Examples

base_dir <- file.path(tempdir(), "slurmjobs_scripts")
dir.create(base_dir)

#   Create a shell script that submits a corresponding R script
job_single(
    file.path(base_dir, "01_should_be_second.sh"),
    logdir = file.path(base_dir, "logs"), create_logdir = TRUE,
    create_shell = TRUE, command = "Rscript 01_should_be_second.R"
)
#> 2025-02-04 17:57:09.812083 creating the logs directory at:  /tmp/RtmpfFvaOX/slurmjobs_scripts/logs
#> 2025-02-04 17:57:09.8135 creating the shell file /tmp/RtmpfFvaOX/slurmjobs_scripts/01_should_be_second.sh
#> To submit the job use: sbatch /tmp/RtmpfFvaOX/slurmjobs_scripts/01_should_be_second.sh
writeLines("# some code", con = file.path(base_dir, "01_should_be_second.R"))

#   Create an array originally designed to be submitted second
job_loop(
    file.path(base_dir, "02_should_be_first.sh"),
    create_shell = TRUE, logdir = file.path(base_dir, "logs"),
    loops = list(
        gene = c("gene_1", "gene_2"), method = c("method_1", "method_2")
    ) 
)
#> 2025-02-04 17:57:09.816394 creating the logs directory at:  /tmp/RtmpfFvaOX/slurmjobs_scripts/logs
#> 2025-02-04 17:57:09.818093 Creating the shell file 02_should_be_first.sh and corresponding R script 02_should_be_first.R
#> To submit the script pair, use: sbatch /tmp/RtmpfFvaOX/slurmjobs_scripts/02_should_be_first.sh

#   Swap the order of the scripts
renumber(base_dir, c("01", "02"), c("02", "01"))

#   Check that the scripts have been properly renamed
list.files(base_dir)
#> [1] "01_should_be_first.R"   "01_should_be_first.sh"  "02_should_be_second.R" 
#> [4] "02_should_be_second.sh" "logs"