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 thechdir
argument tosource
).- echo
Passed through to
source
to control printing while evaluating. Generally you will want to leave this asTRUE
- 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 passFALSE
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 optionhipercow.default_envvars
), and any driver-specific environment variables (seevignette("windows")
). Variables provided here have the highest precedence. You can unset an environment variable by setting it toNA
.- 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.
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 'fd62f089a667fc59696e8a7fc11f8957' using 'example'
task_info(id)
#>
#> ── task fd62f089a667fc59696e8a7fc11f8957 (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-10-08 15:27:12.699108 (moments ago)
#> ! Not started yet (waiting for 70ms)
#> ! 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