compose {acumos} | R Documentation |
Compose a Acumos microservice
Description
compose
generates everything necessary to create a Acumos microservice.
Usage
compose(predict, transform, fit, generate, service, initialize,
aux = list(), name = "R Component", componentVersion="unknown version",
file = "component.zip")
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 |
componentVersion |
string, version 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 official 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
Examples
## 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")
file.remove("component.zip")