Read a slurm batch file and capture the SBATCH options
read_sbatch(x)A named list of the options starting with #SBATCH in the file. The
names are the option names without leading dashes (e.g., "job-name" for
--job-name, or "J" for -J). Options with a value (e.g.,
--time=01:00:00, --time 01:00:00, or -N 2) are stored as character
scalars, while flags without a value (e.g., --exclusive) are stored as
TRUE, so the list can be passed to parse_flags() to recover the options.
If no option is found, then returns an empty list.
The options are read the way Slurm does it: only the #SBATCH
lines located before the first command are used; a line can have more than
one option (e.g., #SBATCH -N2 -n4); quotes group characters (and are
removed) and a backslash escapes the next character; and an unquoted,
unescaped # starts a comment that lasts until the end of the line. A
token that does not start with a dash and follows an option is taken as its
value (e.g., --time 01:00:00), except for options without a value or with
an optional one (e.g., --exclusive, --requeue, --nice), which only take
it attached (--nice=5). Flags can be clustered (e.g., -Hs).
# Reading in an example script
x <- system.file("example.slurm", package="slurmR")
read_sbatch(x)
#> $`job-name`
#> [1] "NameOfTheJob"
#>
#> $output
#> [1] "logfile.out"
#>
#> $array
#> [1] "1-100"
#>
#> $ntasks
#> [1] "1"
#>
#> $partition
#> [1] "NameOfThePartition"
#>