R/renumber.R
renumber.RdThis 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,
expect_matches = TRUE,
recursive_edits = FALSE
)A character(1) path to a directory containing the scripts
to re-order.
A character() vector of prefices to replace among scripts
in base_dir.
A character() vector of replacement prefices among scripts
in base_dir.
A logical(1) indicating whether to expect that all
prefices in pre_before will match a file in base_dir, throwing an error if
not.
A logical(1) indicating whether to recursively search
base_dir for R, shell, and Python scripts and replace any instances of the
prefices in pre_before with the corresponding prefices in pre_after.
Because of the slight risk where prefices are not uniquely identifiable
and unexpected edits take place, the default is FALSE; you must opt in
intentionally.
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"
)
#> 2026-05-12 18:34:27.308574 creating the logs directory at: /tmp/RtmpDp4cGZ/slurmjobs_scripts/logs
#> 2026-05-12 18:34:27.309834 creating the shell file /tmp/RtmpDp4cGZ/slurmjobs_scripts/01_should_be_second.sh
#> To submit the job use: sbatch /tmp/RtmpDp4cGZ/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")
)
)
#> 2026-05-12 18:34:27.312434 creating the logs directory at: /tmp/RtmpDp4cGZ/slurmjobs_scripts/logs
#> 2026-05-12 18:34:27.314 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/RtmpDp4cGZ/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"