getAlgorithmHandler {algorithmia}R Documentation

Creates a new Algorithm Handler which registers the onLoad method (which loads the model or other dependencies for the algorithm) and the apply method which takes in the result of the onLoad method and the input from the user.

Description

Creates a new Algorithm Handler which registers the onLoad method (which loads the model or other dependencies for the algorithm) and the apply method which takes in the result of the onLoad method and the input from the user.

Usage

getAlgorithmHandler(
  applyfunc,
  onLoadMethod = function() {     NULL },
  pipe = "stdin"
)

Arguments

applyfunc

The method that we will call synchronously for each algorithm call. The first argument it will be called with is the user input, followed with the output of the onLoad function.

onLoadMethod

This optional method that is run once when the process first starts. It loads the data required and other shared state for each algorithm call.

pipe

The file which we will read line-by-line to get user input

Value

A new AlgorithmHandler object

Examples

loadPrefix <- function() { "Hello" }
algorithm <- function(input, prefix) { paste(prefix, input) }

#To create an algorithm that returns "Hello" + input:
algo <- getAlgorithmHandler(algorithm, loadPrefix)

[Package algorithmia version 0.3.0 Index]