compose: Compose a Acumos microservice

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/run.R

Description

compose generates everything necessary to create a Acumos microservice.

Usage

1
2
compose(predict, transform, fit, generate, service, initialize,
        aux = list(), name = "R Component", file = "component.amc")

Arguments

predict

predict function (optional)

transform

transform function (optional)

fit

fit function (optional)

generate

generate function (optional)

service

function handling additional non-Acumos requests (optional)

initialize

function for any one-shot initializations of the environment

aux

list of any auxiliary objects that are to be passed to the global workspace of the component.

name

string, name of the component

file

string, filename for the resulting component file

Details

A regular component will have at least one of the three functions predict, transform or fit set in which case those functions are exposed via the Acumos API.

A special component can instead provide the generate function only in which case the generate function is called upon instantiation instead of serving the Acumos API. This is useful when adapting from other inputs than Acumos since the generate function can use arbitrary input methods and then use Acumos API to push to other Acumos components. Similarly, non-Acumos requests can be served using the service call-back function with the signature function(path, query, body, headers) where body is NULL or a raw vector. This interface is experimental and currently not part of the offical API.

The functions can have two special arguments inputs and output which are used to define the types of the input and output data. They have to be named string vectors where the names will match formats of the functions and the string specifies the input type (class). At this point only "character", "integer", "numeric" and "raw" are supported. If those arguments are not present, they default to c(x="character"). If the result of the function is a list, it is assumed that the list holds the outputs, otherwise only one output is used.

The compose() function is called mainly for its side-effect of creating the Acumos API component file, at this point it is a (ZIP) bundle of meta.json (metadata), component.bin (serialized R functions and code) and component.proto (I/O definition)

Value

Structure describing the component (parsed content of the JSON description).

Author(s)

Simon Urbanek

See Also

run

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## pass-through component
compose(transform=identity, name="identity")

## simple addition
compose(transform=function(a, b, inputs=c(a="numeric", b="numeric"), outputs=c(x="numeric")) a + b, name="Addition")

## silly RF trained on Iris
library(randomForest)
compose(predict=function(..., inputs=lapply(iris[-5], class)) as.character(predict(rf, as.data.frame(list(...)))),
        aux = list(rf = randomForest(Species ~ ., data=iris)),
        name="Random Forest")

s-u/acumos documentation built on March 16, 2020, 2:27 a.m.