diff --git a/R/compile.R b/R/compile.R index 5402dfb..874eb4f 100644 --- a/R/compile.R +++ b/R/compile.R @@ -57,7 +57,7 @@ ts_compile.character <- function( x ) - writeLines(src, file) + cat(src, file = file, sep = "\n") invisible() } diff --git a/README.Rmd b/README.Rmd index ce68f40..6495465 100644 --- a/README.Rmd +++ b/README.Rmd @@ -99,9 +99,9 @@ Here's what's currently working: library(ts) myfun <- ts_function(mean, x = ts_numeric(), result = ts_numeric(1)) -myfun(1:5) +myfun$call(1:5) -myfun("hello world") +myfun$call("hello world") cat(readLines("tests/testthat/app.R"), sep = "\n") diff --git a/README.md b/README.md index 85f8e8b..b84c7c2 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,14 @@ type App = { }; ``` +Besides generating the schema as shown above, the app object can also be +‘deployed’ using Rserve: + +``` r +ts_deploy(app, port = 6311, daemon = FALSE) +# listening on port 6311 +``` + ## State of the project Here’s what’s currently working: @@ -86,18 +94,18 @@ Here’s what’s currently working: library(ts) myfun <- ts_function(mean, x = ts_numeric(), result = ts_numeric(1)) -myfun(1:5) -#> Error in myfun(1:5): could not find function "myfun" +myfun$call(1:5) +#> [1] 3 -myfun("hello world") -#> Error in myfun("hello world"): could not find function "myfun" +myfun$call("hello world") +#> Error: Invalid argument 'x': Expected a number cat(readLines("tests/testthat/app.R"), sep = "\n") #> library(ts) #> #> fn_mean <- ts_function(mean, x = ts_numeric(), result = ts_numeric(1)) -#> fn_first <- ts_function(function(x) x[1], -#> x = ts_character(-1), result = ts_character(1) +#> fn_first <- ts_function(function(x = ts_character(-1)) x[1], +#> result = ts_character(1) #> ) #> #> sample_num <- ts_function( @@ -107,23 +115,11 @@ cat(readLines("tests/testthat/app.R"), sep = "\n") #> ) ts_compile("tests/testthat/app.R", file = "") -#> import { } from 'rserve-ts'; +#> import { Robj } from 'rserve-ts'; +#> import { z } from 'zod'; #> -#> character(0) -#> character(0) -#> character(0) +#> +#> const fn_first = Robj.ocap([z.union([z.string(), Robj.character(0)])], Robj.character(1)); +#> const fn_mean = Robj.ocap([z.union([z.number(), z.instanceof(Float64Array)])], Robj.numeric(1)); +#> const sample_num = Robj.ocap([z.instanceof(Float64Array)], Robj.numeric(1)); ``` - -## TODO - - - [ ] Add support for more types - - - [ ] Allow generic types (e.g., `(x: T) => T`) - - - [ ] Add support for conditional return types - - e.g., `const sample = (x: T[], n: N) => N - extends 1 ? T : T[]` - - - [ ] Function overloads? Perhaps just a wrapper around several - function definitions…