From 620be25588da27016f6a54dad24e1ee421314c7b Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Mon, 20 Jan 2025 22:17:12 +1300 Subject: [PATCH] working on deployment methods --- DESCRIPTION | 3 ++- NAMESPACE | 5 +++++ R/function.R | 25 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 05098ce..3da4cb1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,4 +16,5 @@ Config/testthat/edition: 3 Imports: cli, js, - rlang + rlang, + Rserve diff --git a/NAMESPACE b/NAMESPACE index 3eb7ff1..9cfd924 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,15 +8,20 @@ S3method(get_type,ts_function) S3method(get_type,ts_object) S3method(print,ts_function) S3method(print,ts_object) +S3method(ts_app,default) +S3method(ts_app,list) +S3method(ts_app,ts_function) S3method(ts_compile,character) S3method(ts_compile,default) S3method(ts_compile,ts_function) export(check_type) export(get_type) export(is_ts_object) +export(ts_app) export(ts_character) export(ts_compile) export(ts_dataframe) +export(ts_deploy) export(ts_factor) export(ts_function) export(ts_integer) diff --git a/R/function.R b/R/function.R index 8dafc57..40d17c4 100644 --- a/R/function.R +++ b/R/function.R @@ -97,3 +97,28 @@ print.ts_function <- function(x, ...) { cli::cli_text("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(...))) +}