|
1 | 1 | #!/bin/bash |
2 | 2 | ###################################################################### |
3 | | -# A batchtools launch script template for OpenLava |
| 3 | +# A batchtools launch script template for LSF and OpenLava |
4 | 4 | # |
5 | 5 | # Author: Henrik Bengtsson |
6 | 6 | ###################################################################### |
|
29 | 29 | modules <- resources[["modules"]] |
30 | 30 | resources[["modules"]] <- NULL |
31 | 31 |
|
| 32 | + ## Custom "Rscript" command and Rscript arguments |
| 33 | + rscript <- resources[["rscript"]] |
| 34 | + if (is.null(rscript)) { |
| 35 | + rscript <- "Rscript" |
| 36 | + } else { |
| 37 | + if (length(rscript) == 0 || !nzchar(rscript)[1]) stop("Argument 'resources' specifies an empty 'rscript' field") |
| 38 | + rscript[rscript == "*"] <- "Rscript" |
| 39 | + } |
| 40 | + resources[["rscript"]] <- NULL |
| 41 | + rscript_args <- resources[["rscript_args"]] |
| 42 | + resources[["rscript_args"]] <- NULL |
| 43 | + rscript_call <- paste(c(rscript, rscript_args), collapse = " ") |
| 44 | + |
32 | 45 | ## As-is resource specifications |
33 | 46 | job_declarations <- resources[["asis"]] |
34 | 47 | resources[["asis"]] <- NULL |
35 | 48 |
|
36 | | - ## Remaining resources are assumed to be of type '-<key>=<value>' |
| 49 | + ## Remaining resources are assumed to be of type '<key>=<value>' |
37 | 50 | opts <- unlist(resources, use.names = TRUE) |
38 | | - opts <- sprintf("-%s=%s", names(opts), opts) |
39 | | - job_declarations <- sprintf("#BSUB %s", c(job_declarations, opts)) |
| 51 | + opts <- sprintf("%s=%s", names(opts), opts) |
| 52 | + job_declarations <- sprintf("#BSUB %s", c(job_declarations, sprintf("-%s", opts))) |
40 | 53 | writeLines(job_declarations) |
41 | 54 | %> |
42 | 55 |
|
|
78 | 91 | echo "Session information:" |
79 | 92 | echo "- timestamp: $(date +"%Y-%m-%d %H:%M:%S%z")" |
80 | 93 | echo "- hostname: $(hostname)" |
81 | | - |
82 | | -if command -v Rscript &> /dev/null; then |
83 | | - >&2 echo "ERROR: 'Rscript' could not be found. Maybe you need to specify which environment modules to load in the 'resources' argument, e.g. 'plan(future.batchtools::batchtools_openlava, resources = list(modules = c(\"r\")))'. The search PATH for 'Rscript' was ${PATH}" |
| 94 | +echo "- Rscript call: <%= rscript_call %>" |
| 95 | +if ! command -v <%= rscript[1] %> &> /dev/null; then |
| 96 | + >&2 echo "ERROR: Argument 'resources' specifies a non-existing 'Rscript' launch command: <%= rscript[1] %>. Maybe you need to specify which environment modules to load in the 'resources' argument, e.g. 'plan(future.batchtools::batchtools_slurm, resources = list(modules = c(\"r\")))'. The search PATH for '%<= rscript[1] %>' was ${PATH}" |
84 | 97 | exit 1 |
85 | 98 | fi |
86 | | - |
87 | | -echo "- Rscript path: $(which Rscript)" |
88 | | -echo "- Rscript version: $(Rscript --version)" |
89 | | -echo "- Rscript library paths: $(Rscript -e "cat(shQuote(.libPaths()), sep = ' ')")" |
| 99 | +echo "- Rscript version: $(<%= paste(rscript, collapse = " ") %> --version)" |
| 100 | +echo "- Rscript library paths: $(<%= rscript_call %> -e "cat(shQuote(.libPaths()), sep = ' ')")" |
90 | 101 | echo |
91 | 102 |
|
92 | 103 |
|
93 | 104 | ## Launch R and evaluate the batchtools R job |
94 | | -echo "Rscript -e 'batchtools::doJobCollection()' ..." |
| 105 | +echo "Calling 'batchtools::doJobCollection()' ..." |
95 | 106 | echo "- job name: '<%= job.name %>'" |
96 | 107 | echo "- job log file: '<%= log.file %>'" |
97 | 108 | echo "- job uri: '<%= uri %>'" |
98 | | -Rscript -e 'batchtools::doJobCollection("<%= uri %>")' |
| 109 | +<%= rscript_call %> -e 'batchtools::doJobCollection("<%= uri %>")' |
99 | 110 | res=$? |
100 | 111 | echo " - exit code: ${res}" |
101 | | -echo "Rscript -e 'batchtools::doJobCollection()' ... done" |
| 112 | +echo "Calling 'batchtools::doJobCollection()' ... done" |
102 | 113 | echo |
103 | 114 |
|
104 | 115 | <% if (details) { %> |
|
0 commit comments