File: clusterFunctionsInteractive.R

package info (click to toggle)
r-cran-batchtools 0.9.15%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,416 kB
  • sloc: ansic: 172; sh: 156; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,755 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#' @title ClusterFunctions for Sequential Execution in the Running R Session
#'
#' @description
#' All jobs are executed sequentially using the current R process in which \code{\link{submitJobs}} is called.
#' Thus, \code{submitJob} blocks the session until the job has finished.
#' The main use of this \code{ClusterFunctions} implementation is to test and debug programs on a local computer.
#'
#' Listing jobs returns an empty vector (as no jobs can be running when you call this)
#' and \code{killJob} is not implemented for the same reasons.
#'
#' @param external [\code{logical(1)}]\cr
#'   If set to \code{TRUE}, jobs are started in a fresh R session instead of currently active but still
#'   waits for its termination.
#'   Default is \code{FALSE}.
#' @param write.logs [\code{logical(1)}]\cr
#'   Sink the output to log files. Turning logging off can increase the speed of
#'   calculations but makes it very difficult to debug.
#'   Default is \code{TRUE}.
#' @inheritParams makeClusterFunctions
#' @return [\code{\link{ClusterFunctions}}].
#' @family ClusterFunctions
#' @export
makeClusterFunctionsInteractive = function(external = FALSE, write.logs = TRUE, fs.latency = 0) {
  assertFlag(external)
  assertFlag(write.logs)

  submitJob = function(reg, jc) {
    assertRegistry(reg, writeable = TRUE)
    assertClass(jc, "JobCollection")
    if (external) {
      runOSCommand(Rscript(), sprintf("-e \"batchtools::doJobCollection('%s', output = '%s')\"", jc$uri, jc$log.file))
    } else {
      doJobCollection(jc, output = jc$log.file)
    }
    makeSubmitJobResult(status = 0L, batch.id = "cfInteractive")
  }

  makeClusterFunctions(name = "Interactive", submitJob = submitJob, store.job.collection = external, fs.latency = fs.latency)
}