inst/testme/test-script,validate.R

#' @tags skip_on_cran

library(future)

message("*** Job-script validation ...")

bin <- Sys.which("bash")
if (utils::file_test("-f", bin) && .Platform[["OS.type"]] != "windows") {
  tmpl <- tempfile(fileext = ".tmpl")
  on.exit(file.remove(tmpl), add = TRUE)

  message("- Template with syntax error")
  writeLines(c("#!/bin/bash", "if true; then", "echo 'oops'"), con = tmpl)
  plan(future.batchtools::batchtools_bash, template = tmpl)
  res <- tryCatch({
    f <- future(42L)
    value(f)
  }, error = identity)
  print(res)
  stopifnot(inherits(res, "error"), grepl("syntax error", conditionMessage(res)))

  ## Direct tests of validate_job_script() are in test-validate_job_script.R

  message("- Valid template")
  ## Use the full path to 'Rscript', because 'R CMD check' puts a stub
  ## 'Rscript' on the PATH that refuses to run
  rscript <- file.path(R.home("bin"), "Rscript")
  plan(future.batchtools::batchtools_bash, resources = list(rscript = rscript))
  stopifnot(value(future(42L)) == 42L)
} else {
  message("Skipping: 'bash' is not available")
}

message("*** Job-script validation ... DONE")

Try the future.batchtools package in your browser

Any scripts or data that you put into this service are public.

future.batchtools documentation built on Nov. 23, 2026, 1:07 a.m.