nimbleFunction: create a nimbleFunction

View source: R/nimbleFunction_core.R

nimbleFunctionR Documentation

create a nimbleFunction

Description

create a nimbleFunction from a setup function, run function, possibly other methods, and possibly inheritance via contains

Usage

nimbleFunction(
  setup = NULL,
  run = function() {
 },
  methods = list(),
  globalSetup = NULL,
  contains = NULL,
  buildDerivs = list(),
  name = NA,
  check = getNimbleOption("checkNimbleFunction"),
  where = getNimbleFunctionEnvironment()
)

Arguments

setup

An optional R function definition for setup processing.

run

An optional NIMBLE function definition that executes the primary job of the nimbleFunction

methods

An optional named list of NIMBLE function definitions for other class methods.

globalSetup

For internal use only

contains

An optional object returned from nimbleFunctionVirtual that defines arguments and returnTypes for run and/or methods, to which the current nimbleFunction must conform

buildDerivs

A list of names of function methods for which to build derivatives capabilities.

name

An optional name used internally, for example in generated C++ code. Usually this is left blank and NIMBLE provides a name.

check

Boolean indicating whether to check the run code for function calls that NIMBLE cannot compile. Checking can be turned off for all calls to nimbleFunction using nimbleOptions(checkNimbleFunction = FALSE).

where

An optional where argument passed to setRefClass for where the reference class definition generated for this nimbleFunction will be stored. This is needed due to R package namespace issues but should never need to be provided by a user.

Details

This is the main function for defining nimbleFunctions. A lot of information is provided in the NIMBLE User Manual, so only a brief summary will be given here.

If a setup function is provided, then nimbleFunction returns a generator: a function that when called with arguments for the setup function will execute that function and return a specialized nimbleFunction. The run and other methods can be called using $ like in other R classes, e.g. nf$run(). The methods can use objects that were created in or passed to the setup function.

If no setup function is provided, then nimbleFunction returns a function that executes the run function. It is not a generator in this case, and no other methods can be provided.

If one wants a generator but does not need any setup arguments or code, setup = TRUE can be used.

See the NIMBLE User Manual for examples.

For more information about the contains argument, see the section on nimbleFunctionLists.

Author(s)

NIMBLE development team


nimble documentation built on Sept. 11, 2024, 7:10 p.m.