working on deployment methods

This commit is contained in:
Tom Elliott 2025-01-20 22:17:12 +13:00
parent 600aa1962a
commit 620be25588
3 changed files with 32 additions and 1 deletions

View File

@ -16,4 +16,5 @@ Config/testthat/edition: 3
Imports: Imports:
cli, cli,
js, js,
rlang rlang,
Rserve

View File

@ -8,15 +8,20 @@ S3method(get_type,ts_function)
S3method(get_type,ts_object) S3method(get_type,ts_object)
S3method(print,ts_function) S3method(print,ts_function)
S3method(print,ts_object) S3method(print,ts_object)
S3method(ts_app,default)
S3method(ts_app,list)
S3method(ts_app,ts_function)
S3method(ts_compile,character) S3method(ts_compile,character)
S3method(ts_compile,default) S3method(ts_compile,default)
S3method(ts_compile,ts_function) S3method(ts_compile,ts_function)
export(check_type) export(check_type)
export(get_type) export(get_type)
export(is_ts_object) export(is_ts_object)
export(ts_app)
export(ts_character) export(ts_character)
export(ts_compile) export(ts_compile)
export(ts_dataframe) export(ts_dataframe)
export(ts_deploy)
export(ts_factor) export(ts_factor)
export(ts_function) export(ts_function)
export(ts_integer) export(ts_integer)

View File

@ -97,3 +97,28 @@ print.ts_function <- function(x, ...) {
cli::cli_text("Return type:") cli::cli_text("Return type:")
cat(x$result$return_type) cat(x$result$return_type)
} }
#' Generate an Rserve app from a ts function
#'
#' Anything that is not a function simply returns itself.
#' However, functions are wrapped with `Rserve::ocap()`,
#' and the result is subsequently wrapped with `ts_app()`.
#' @param x A ts function object (`ts_function()`)
#' @export
#' @md
ts_app <- function(x) UseMethod("ts_app")
#' @export
ts_app.default <- function(x) {
x
}
#' @export
ts_app.list <- function(x) {
lapply(x, ts_app)
}
#' @export
ts_app.ts_function <- function(x) {
Rserve::ocap(function(...) ts_app(x$call(...)))
}