38 lines
1.2 KiB
R
38 lines
1.2 KiB
R
% Generated by roxygen2: do not edit by hand
|
|
% Please edit documentation in R/function.R
|
|
\name{ts_function}
|
|
\alias{ts_function}
|
|
\title{TS function definition}
|
|
\usage{
|
|
ts_function(f, ..., result = ts_void())
|
|
}
|
|
\arguments{
|
|
\item{f}{an R function}
|
|
|
|
\item{...}{argument definitions (only required if f does not specify these in its formals)}
|
|
|
|
\item{result}{return type (ignored if overloads are provided)}
|
|
}
|
|
\description{
|
|
TS function definition
|
|
}
|
|
\details{
|
|
Defining functions is the core of writing Rserve apps.
|
|
Functions are referred to as \emph{object capabilities} (ocaps),
|
|
as they are 'objects' that allow Javascript to access capabilities
|
|
of R with a restricted interface. Only arguments can be adjusted.
|
|
|
|
TS functions can be defined using existing (named) or anonymous functions.
|
|
Anonymous functions are useful in that the arguments to the functions
|
|
can explicitly be defined with their types as formal arguments:
|
|
|
|
\if{html}{\out{<div class="sourceCode">}}\preformatted{ts_function(function(x = ts_integer(), y = ts_string()) \{ ... \})
|
|
}\if{html}{\out{</div>}}
|
|
}
|
|
\examples{
|
|
f <- ts_function(function(x = ts_integer(1), y = ts_character(1)) {
|
|
x + nchar(y)
|
|
}, result = ts_integer(1))
|
|
f$call(1, "hello")
|
|
}
|