#!/bin/bash
# From https://github.com/mllg/batchtools/blob/master/inst/templates/

<%
log.file = normalizePath(log.file, winslash = "/", mustWork = FALSE)
if (!"ncpus" %in% names(resources)) {
  resources$ncpus = 1
}
if (!"walltime" %in% names(resources)) {
  resources$walltime = 48 * 3600
}
-%>

#SBATCH --job-name=<%= job.name %>
#SBATCH --output=<%= log.file %>
#SBATCH --error=<%= log.file %>
#SBATCH --ntasks=1

<%= if (!is.null(resources$walltime)) { %>
#SBATCH --time=<%= ceiling(resources$walltime / 60) %>
<%= } %>

<%= if (!is.null(resources$ncpus)) { %>
#SBATCH --cpus-per-task=<%= resources$ncpus %>
<%= } %>

<%= if (!is.null(resources$memory)) { %>
#SBATCH --mem-per-cpu=<%= resources$memory %>
<%= } %>

<%= if (array.jobs) sprintf("#SBATCH --array=1-%i", nrow(jobs)) else "" %>

## Initialize work environment like
## source /etc/profile
source /etc/profile

# module load R # Uncomment if R is an environment module.
Rscript -e 'batchtools::doJobCollection("<%= uri %>")'
