Skip to contents

Create a task from a script. This will arrange to run the file script via hipercow. The script must exist within your hipercow root, but you may change to the directory of the script as it executes (otherwise we will evaluate from your current directory relative to the hipercow root, as usual).

Usage

task_create_script(
  script,
  chdir = FALSE,
  echo = TRUE,
  environment = "default",
  driver = NULL,
  resources = NULL,
  envvars = NULL,
  parallel = NULL,
  root = NULL
)

Arguments

script

Path for the script

chdir

Logical, indicating if we should change the working directory to the directory containing script before executing it (similar to the chdir argument to source).

echo

Passed through to source to control printing while evaluating. Generally you will want to leave this as TRUE

environment

Name of the hipercow environment to evaluate the task within.

driver

Name of the driver to use to submit the task. The default (NULL) depends on your configured drivers; if you have no drivers configured no submission happens (or indeed is possible). If you have exactly one driver configured we'll submit your task with it. If you have more than one driver configured, then we will error, though in future versions we may fall back on a default driver if you have one configured. If you pass FALSE here, submission is prevented even if you have no driver configured.

resources

A list generated by hipercow_resources giving the cluster resource requirements to run your task.

envvars

Environment variables as generated by hipercow_envvars, which you might use to control your task. These will be combined with the default environment variables (see vignettes("details"), this can be overridden by the option hipercow.default_envvars), and any driver-specific environment variables (see vignette("windows")). Variables provided here have the highest precedence. You can unset an environment variable by setting it to NA.

parallel

Parallel configuration as generated by hipercow_parallel, which defines which method, if any, will be used to initialise your task for parallel execution.

root

A hipercow root, or path to it. If NULL we search up your directory tree.

Value

A task id, a string of hex characters. Use this to interact with the task.

Examples

cleanup <- hipercow_example_helper()
#>  This example uses a special helper

# Create a small script; this would usually be several lines of
# course.  The script will need to do something as a side effect
# to be worth calling, so here we write a file.
writeLines("saveRDS(mtcars, 'data.rds')", "script.R")

# Now create a task from this script
id <- task_create_script("script.R")
#>  Submitted task '64122aa3935b492b9892cc503e97c61e' using 'example'
task_info(id)
#> 
#> ── task 64122aa3935b492b9892cc503e97c61e (submitted) ───────────────────────────
#>  Submitted with 'example'
#>  Task type: script
#>   • Script: script.R
#>   • Options: chdir = FALSE, echo = TRUE
#>   • Environment: default
#>     R_GC_MEM_GROW: 3
#>  Created at 2024-08-16 20:22:59.162203 (moments ago)
#> ! Not started yet (waiting for 66ms)
#> ! Not finished yet (waiting to start)
task_wait(id)
#> [1] TRUE
task_result(id)
#> NULL
dir()
#> [1] "data.rds" "hipercow" "script.R"

cleanup()
#>  Cleaning up example