R/tar_resources_future.R

Defines functions tar_resources_future

Documented in tar_resources_future

#' @title Target resources: `future` high-performance computing
#' @export
#' @family resources
#' @description Create the `future` argument of `tar_resources()`
#'   to specify optional high-performance computing settings
#'   for `tar_make_future()`.
#'   This is how to supply the `resources`
#'   argument of `future::future()` for `targets`.
#'   Resources supplied through
#'   `future::plan()` and `future::tweak()` are completely ignored.
#'   For details, see the documentation of the `future` R package
#'   and the corresponding argument names in this help file.
#' @inheritSection tar_resources Resources
#' @return Object of class `"tar_resources_future"`, to be supplied
#'   to the `future` argument of `tar_resources()`.
#' @param plan A `future::plan()` object or `NULL`,
#'   a `target`-specific `future` plan. Defaults to `NULL`.
#' @param resources Named list, `resources` argument to
#'   `future::future()`. This argument is not supported in
#'   some versions of `future`. For versions of `future`
#'   where `resources` is not supported, instead supply `resources`
#'   to `future::tweak()` and assign the returned plan to the `plan` argument
#'   of `tar_resources_future()`.
#'   The default value of `resources` in `tar_resources_future()`
#'   is an empty list.
#' @examples
#' # Somewhere in you target script file (usually _targets.R):
#' tar_target(
#'   name,
#'   command(),
#'   resources = tar_resources(
#'     future = tar_resources_future(resources = list(n_cores = 2))
#'   )
#' )
tar_resources_future <- function(
  plan = NULL,
  resources = targets::tar_option_get("resources")$future$resources
) {
  resources <- resources %|||% list()
  out <- resources_future_init(
    plan = plan,
    resources = resources
  )
  resources_validate(out)
  out
}

Try the targets package in your browser

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

targets documentation built on Oct. 3, 2024, 1:11 a.m.