| Service {parabar} | R Documentation |
Service
Description
This is an interface that defines the operations available on a
Backend implementation. Backend implementations and the
Context class must implement this interface.
Methods
Public methods
Method new()
Create a new Service object.
Usage
Service$new()
Returns
Instantiating this call will throw an error.
Method start()
Start the backend.
Usage
Service$start(specification)
Arguments
specificationAn object of class
Specificationthat contains the backend configuration.
Returns
This method returns void. The resulting backend must be stored in the
.cluster private field on the Backend abstract class,
and accessible to any concrete backend implementations via the active
binding cluster.
Method stop()
Stop the backend.
Usage
Service$stop()
Returns
This method returns void.
Method clear()
Remove all objects from the backend. This function is equivalent to
calling rm(list = ls(all.names = TRUE)) on each node in the
backend.
Usage
Service$clear()
Details
This method is ran by default when the backend is started.
Returns
This method returns void.
Method peek()
Inspect the backend for variables available in the .GlobalEnv.
Usage
Service$peek()
Returns
This method returns a list of character vectors, where each element
corresponds to a node in the backend. The character vectors contain
the names of the variables available in the .GlobalEnv on each
node.
Method export()
Export variables from a given environment to the backend.
Usage
Service$export(variables, environment)
Arguments
variablesA character vector of variable names to export.
environmentAn environment object from which to export the variables.
Returns
This method returns void.
Method evaluate()
Evaluate an arbitrary expression on the backend.
Usage
Service$evaluate(expression)
Arguments
expressionAn unquoted expression to evaluate on the backend.
Returns
This method returns the result of the expression evaluation.
Method sapply()
Run a task on the backend akin to parallel::parSapply().
Usage
Service$sapply(x, fun, ...)
Arguments
xAn atomic vector or list to pass to the
funfunction.funA function to apply to each element of
x....Additional arguments to pass to the
funfunction.
Returns
This method returns void. The output of the task execution must be
stored in the private field .output on the Backend
abstract class, and is accessible via the get_output() method.
Method lapply()
Run a task on the backend akin to parallel::parLapply().
Usage
Service$lapply(x, fun, ...)
Arguments
xAn atomic vector or list to pass to the
funfunction.funA function to apply to each element of
x....Additional arguments to pass to the
funfunction.
Returns
This method returns void. The output of the task execution must be
stored in the private field .output on the Backend
abstract class, and is accessible via the get_output() method.
Method apply()
Run a task on the backend akin to parallel::parApply().
Usage
Service$apply(x, margin, fun, ...)
Arguments
xAn array to pass to the
funfunction.marginA numeric vector indicating the dimensions of
xthefunfunction should be applied over. For example, for a matrix,margin = 1indicates applyingfunrows-wise,margin = 2indicates applyingfuncolumns-wise, andmargin = c(1, 2)indicates applyingfunelement-wise. Named dimensions are also possible depending onx. Seeparallel::parApply()andbase::apply()for more details.funA function to apply to
xaccording to themargin....Additional arguments to pass to the
funfunction.
Returns
This method returns void. The output of the task execution must be
stored in the private field .output on the Backend
abstract class, and is accessible via the get_output() method.
Method get_output()
Get the output of the task execution.
Usage
Service$get_output(...)
Arguments
...Additional optional arguments that may be used by concrete implementations.
Details
This method fetches the output of the task execution after calling
the sapply() method. It returns the output and immediately removes
it from the backend. Therefore, subsequent calls to this method are
not advised. This method should be called after the execution of a
task.
Returns
A vector, matrix, or list of the same length as x, containing the
results of the fun. The output format differs based on the specific
operation employed. Check out the documentation for the apply
operations of parallel::parallel for more information.
Method clone()
The objects of this class are cloneable with this method.
Usage
Service$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
Backend, SyncBackend, AsyncBackend,
and Context.