<\/div>` ) .join(\"\")} `; }); // style.css :root { font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; line-height: 1.5; font-weight: 400; color-scheme: light dark; color: rgba(255, 255, 255, 0.87); background-color: #242424; font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } a { font-weight: 500; color: #646cff; text-decoration: inherit; } a:hover { color: #535bf2; } body { margin: 0; display: flex; place-items: center; min-width: 320px; min-height: 100vh; } h1 { font-size: 3.2em; line-height: 1.1; } #app { max-width: 1280px; margin: 0 auto; padding: 2rem; text-align: center; } .logo { height: 6em; padding: 1.5em; will-change: filter; transition: filter 300ms; } .logo:hover { filter: drop-shadow(0 0 2em #646cffaa); } .logo.vanilla:hover { filter: drop-shadow(0 0 2em #3178c6aa); } .card { padding: 2em; } .read-the-docs { color: #888; } button { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; font-size: 1em; font-weight: 500; font-family: inherit; background-color: #1a1a1a; cursor: pointer; transition: border-color 0.25s; } button:hover { border-color: #646cff; } button:focus, button:focus-visible { outline: 4px auto -webkit-focus-ring-color; } input { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; font-size: 1em; font-weight: 500; font-family: inherit; background-color: #1a1a1a; color: #fff; outline: none; } input:hover { border-color: #646cff; } input:focus, input:focus-visible { outline: 4px auto -webkit-focus-ring-color; } @media (prefers-color-scheme: light) { :root { color: #213547; background-color: #ffffff; } a:hover { color: #747bff; } button { background-color: #f9f9f9; } input { background-color: #f9f9f9; color: #000; } }"},{"path":"http://tomelliott.co.nz/ts/articles/simple-react-app.html","id":"run-the-app","dir":"Articles","previous_headings":"","what":"Run the app","title":"Build a simple ReactJS app","text":"run app, start Rserve server: start Vite server: now able see app running http://localhost:5173 (similar, see console output).","code":"Rscript src/faithful-app.rserve.R pnpm run dev"},{"path":"http://tomelliott.co.nz/ts/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Tom Elliott. Author, maintainer.","code":""},{"path":"http://tomelliott.co.nz/ts/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Elliott T (2025). ts: Helper Functions Writing Type-safe Functions rserve-ts. R package version 0.1.0, http://tomelliott.co.nz/ts/.","code":"@Manual{, title = {ts: Helper Functions for Writing Type-safe Functions for rserve-ts}, author = {Tom Elliott}, year = {2025}, note = {R package version 0.1.0}, url = {http://tomelliott.co.nz/ts/}, }"},{"path":"http://tomelliott.co.nz/ts/index.html","id":"ts-write-apps-with-r-rserve-and-typescript","dir":"","previous_headings":"","what":"Helper Functions for Writing Type-safe Functions for rserve-ts","title":"Helper Functions for Writing Type-safe Functions for rserve-ts","text":"ts package makes easy users write functions can used rserve-ts applications.","code":""},{"path":"http://tomelliott.co.nz/ts/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Helper Functions for Writing Type-safe Functions for rserve-ts","text":"can install development version ts GitHub :","code":"# install.packages(\"devtools\") devtools::install_github(\"tmelliott/ts\")"},{"path":"http://tomelliott.co.nz/ts/index.html","id":"example","dir":"","previous_headings":"","what":"Example","title":"Helper Functions for Writing Type-safe Functions for rserve-ts","text":"Writing functions easy, just use ts_*() functions define formals return types. use ts_compile() generate TypeScript schemas: can import rserve-ts application. See tests/testthat/sampler example. also possible generate sourceable file deploy Rserve instance app code using ts_deploy():","code":"# demo.R library(ts) addFn <- ts_function( function(a = ts_numeric(1), b = ts_numeric(1)) a + b, result = ts_numeric(1) ) sampleFn <- ts_function( function(x = ts_character(), n = ts_integer(1)) sample(x, n), result = ts_character() ) app <- ts_function( function() { list( add = addFn, sample = sampleFn ) }, result = ts_list( add = addFn, sample = sampleFn ) ) # TODO: specify exactly which functions to export in the entry point # ts_export(app) import { Robj } from 'rserve-ts'; import { z } from 'zod'; const addFn = Robj.ocap([z.number(), z.number()], Robj.numeric(1)); const app = Robj.ocap([], Robj.list({ add: Robj.ocap(), sample: Robj.ocap() }) ); const sampleFn = Robj.ocap( [z.union([z.string(), z.array(z.string())]), z.number()], Robj.character() ); export default { addFn, app, sampleFn }; ts_deploy(app) # run with: Rscript app.rserve.R"},{"path":"http://tomelliott.co.nz/ts/reference/ts_app.html","id":null,"dir":"Reference","previous_headings":"","what":"Generate an Rserve app from a ts function — ts_app","title":"Generate an Rserve app from a ts function — ts_app","text":"Anything function simply returns . However, functions wrapped Rserve::ocap(), result subsequently wrapped ts_app().","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_app.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Generate an Rserve app from a ts function — ts_app","text":"","code":"ts_app(x)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_app.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Generate an Rserve app from a ts function — ts_app","text":"x ts function object (ts_function())","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_app.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Generate an Rserve app from a ts function — ts_app","text":"object class 'OCref', see Rserve::ocap()","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_app.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Generate an Rserve app from a ts function — ts_app","text":"","code":"f <- ts_function(function(x = ts_integer(1), y = ts_character(1)) { x + nchar(y) }, result = ts_integer(1)) app <- ts_app(f) # class of 'OCref' # this can now be used in an Rserve application, for example"},{"path":"http://tomelliott.co.nz/ts/reference/ts_character.html","id":null,"dir":"Reference","previous_headings":"","what":"Character or string type — ts_character","title":"Character or string type — ts_character","text":"Strings represented Zod schema either string (z.string()), string array (z.array(z.string())).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_character.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Character or string type — ts_character","text":"","code":"ts_character(n = -1L)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_character.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Character or string type — ts_character","text":"n length string vector. n = 1 single string expected. n = 0 length expected. n > 1 string vector length n expected.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_character.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Character or string type — ts_character","text":"ts object accepts strings string vectors length n.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_character.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Character or string type — ts_character","text":"","code":"x <- ts_character(1) x$check(\"a\") #> [1] \"a\""},{"path":"http://tomelliott.co.nz/ts/reference/ts_compile.html","id":null,"dir":"Reference","previous_headings":"","what":"Compile R functions — ts_compile","title":"Compile R functions — ts_compile","text":"Generates TypeScript schema given R function file path. path, R app also generated.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_compile.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compile R functions — ts_compile","text":"","code":"ts_compile(f, ..., name, filename)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_compile.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compile R functions — ts_compile","text":"f function file path ... Additional arguments (passed ts_deploy) name name function filename base file path write TypeScript schema R app (optional, uses [path f].rserve default). .R .ts file extensions appended automatically. \"\", output printed standard output console (see cat).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_compile.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compile R functions — ts_compile","text":"Character vector TypeScript schema, NULL writing file","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_dataframe.html","id":null,"dir":"Reference","previous_headings":"","what":"Typed dataframe — ts_dataframe","title":"Typed dataframe — ts_dataframe","text":"essentially list, elements must names length.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_dataframe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Typed dataframe — ts_dataframe","text":"","code":"ts_dataframe(...)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_dataframe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Typed dataframe — ts_dataframe","text":"... Named types.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_dataframe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Typed dataframe — ts_dataframe","text":"ts object accepts data frames specified types.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_dataframe.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Typed dataframe — ts_dataframe","text":"","code":"x <- ts_dataframe(a = ts_integer(1), b = ts_character(1)) x$check(data.frame(a = 1L, b = \"a\")) #> a b #> 1 1 a"},{"path":"http://tomelliott.co.nz/ts/reference/ts_deploy.html","id":null,"dir":"Reference","previous_headings":"","what":"Deploy a ts Rserve app — ts_deploy","title":"Deploy a ts Rserve app — ts_deploy","text":"Deploy ts Rserve app","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_deploy.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Deploy a ts Rserve app — ts_deploy","text":"","code":"ts_deploy( f, file = sprintf(\"%s.rserve.R\", tools::file_path_sans_ext(f)), init = NULL, port = 6311, run = c(\"no\", \"here\", \"background\"), silent = FALSE )"},{"path":"http://tomelliott.co.nz/ts/reference/ts_deploy.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Deploy a ts Rserve app — ts_deploy","text":"f path application files file file write deployment script init Names objects (ts_functions) make available initialisation function port port deploy app run Whether run deployment script, takes values \"\", \"\", \"background\" silent Whether print deployment script","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_deploy.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Deploy a ts Rserve app — ts_deploy","text":"NULL, called open Rserve instance","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_factor.html","id":null,"dir":"Reference","previous_headings":"","what":"Typed factor — ts_factor","title":"Typed factor — ts_factor","text":"Factors integers labels. JS side, always represented string array (even one value - yay!).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_factor.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Typed factor — ts_factor","text":"","code":"ts_factor(levels = NULL)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_factor.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Typed factor — ts_factor","text":"levels character vector levels (optional).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_factor.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Typed factor — ts_factor","text":"ts object accepts factors specified levels.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_factor.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Typed factor — ts_factor","text":"","code":"x <- ts_factor(levels = c(\"a\", \"b\")) x$check(factor(\"a\", levels = c(\"a\", \"b\"))) #> [1] a #> Levels: a b if (FALSE) { # \\dontrun{ # this will fail x$check(\"a\") x$check(factor(\"c\", levels = c(\"a\", \"b\", \"c\"))) } # }"},{"path":"http://tomelliott.co.nz/ts/reference/ts_function.html","id":null,"dir":"Reference","previous_headings":"","what":"TS function definition — ts_function","title":"TS function definition — ts_function","text":"TS function definition","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_function.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"TS function definition — ts_function","text":"","code":"ts_function(f, ..., result = ts_void())"},{"path":"http://tomelliott.co.nz/ts/reference/ts_function.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"TS function definition — ts_function","text":"f R function ... argument definitions (required f specify formals) result return type (ignored overloads provided)","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_function.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"TS function definition — ts_function","text":"Defining functions core writing Rserve apps. Functions referred object capabilities (ocaps), 'objects' allow Javascript access capabilities R restricted interface. arguments can adjusted. TS functions can defined using existing (named) anonymous functions. Anonymous functions useful arguments functions can explicitly defined types formal arguments:","code":"ts_function(function(x = ts_integer(), y = ts_string()) { ... })"},{"path":"http://tomelliott.co.nz/ts/reference/ts_function.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"TS function definition — ts_function","text":"","code":"f <- ts_function(function(x = ts_integer(1), y = ts_character(1)) { x + nchar(y) }, result = ts_integer(1)) f$call(1, \"hello\") #> [1] 6"},{"path":"http://tomelliott.co.nz/ts/reference/ts_integer.html","id":null,"dir":"Reference","previous_headings":"","what":"Integer type — ts_integer","title":"Integer type — ts_integer","text":"Integers represented Zod schema either number (z.number()), Int32Array (z.instanceof(Int32Array)).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_integer.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Integer type — ts_integer","text":"","code":"ts_integer(n = -1L)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_integer.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Integer type — ts_integer","text":"n length integer vector. n = 1 single integer expected. n = 0 length expected. n > 1 integer vector length n expected.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_integer.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Integer type — ts_integer","text":"ts object accepts integer scalars vectors length n.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_integer.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Integer type — ts_integer","text":"","code":"x <- ts_integer(1) x$check(1L) #> [1] 1 if (FALSE) { # \\dontrun{ # this will fail x$check(1:10) } # }"},{"path":"http://tomelliott.co.nz/ts/reference/ts_list.html","id":null,"dir":"Reference","previous_headings":"","what":"Typed list — ts_list","title":"Typed list — ts_list","text":"list vector robjects, may may named.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_list.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Typed list — ts_list","text":"","code":"ts_list(...)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_list.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Typed list — ts_list","text":"... list types, named unnamed.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_list.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Typed list — ts_list","text":"ts object accepts lists specified types.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_list.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Typed list — ts_list","text":"","code":"x <- ts_list(a = ts_integer(1), b = ts_character(1)) x$check(list(a = 1L, b = \"a\")) #> $a #> [1] 1 #> #> $b #> [1] \"a\" #>"},{"path":"http://tomelliott.co.nz/ts/reference/ts_logical.html","id":null,"dir":"Reference","previous_headings":"","what":"Logical or boolean type — ts_logical","title":"Logical or boolean type — ts_logical","text":"Booleans represented Zod schema either boolean (z.boolean()), typed Uint8Array (z.instanceof(Uint8Array)).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_logical.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Logical or boolean type — ts_logical","text":"","code":"ts_logical(n = -1L)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_logical.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Logical or boolean type — ts_logical","text":"n length boolean vector. n = 1 single boolean expected. n = 0 length expected. n > 1 boolean vector length n expected.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_logical.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Logical or boolean type — ts_logical","text":"ts object accepts logical scalars vectors length n.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_logical.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Logical or boolean type — ts_logical","text":"","code":"x <- ts_logical(1) x$check(TRUE) #> [1] TRUE if (FALSE) { # \\dontrun{ # this will fail x$check(5) } # }"},{"path":"http://tomelliott.co.nz/ts/reference/ts_null.html","id":null,"dir":"Reference","previous_headings":"","what":"Null type — ts_null","title":"Null type — ts_null","text":"type accepts NULL. function return types, use ts_void.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_null.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Null type — ts_null","text":"","code":"ts_null()"},{"path":"http://tomelliott.co.nz/ts/reference/ts_null.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Null type — ts_null","text":"ts object accepts NULL.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_null.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Null type — ts_null","text":"","code":"x <- ts_null() x$check(NULL) #> NULL"},{"path":"http://tomelliott.co.nz/ts/reference/ts_numeric.html","id":null,"dir":"Reference","previous_headings":"","what":"Numeric type — ts_numeric","title":"Numeric type — ts_numeric","text":"Numbers represented Zod schema either number (z.number()), Float64Array (z.instanceof(Float64Array)).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_numeric.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Numeric type — ts_numeric","text":"","code":"ts_numeric(n = -1L)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_numeric.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Numeric type — ts_numeric","text":"n length numeric vector. n = 1 single number expected. n = 0 length expected. n > 1 numeric vector length n expected.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_numeric.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Numeric type — ts_numeric","text":"ts object accepts numeric scalars vectors length n.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_numeric.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Numeric type — ts_numeric","text":"","code":"x <- ts_numeric(1) x$check(1) #> [1] 1 if (FALSE) { # \\dontrun{ # this will fail x$check(c(1, 2, 3)) x$check(\"a\") } # }"},{"path":"http://tomelliott.co.nz/ts/reference/ts_object.html","id":null,"dir":"Reference","previous_headings":"","what":"Typed object (internal use only) — ts_object","title":"Typed object (internal use only) — ts_object","text":"base type typed objects, can used define custom types.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_object.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Typed object (internal use only) — ts_object","text":"","code":"ts_object( input_type = \"any\", return_type = \"any\", default = NULL, check = function() stop(\"Not implemented\"), generic = FALSE ) is_ts_object(x) get_type(x, which = c(\"input\", \"return\")) check_type(type, x)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_object.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Typed object (internal use only) — ts_object","text":"input_type type object Typescript expect send R. return_type type object Typescript expects recieve R. default default value object. check function checks object returns valid. operates R side mostly development debugging purposes. developer ensure functions return correct type object always. generic logical, TRUE object generic type. x object type get, either \"input\" \"return\" type ts object","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_object.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Typed object (internal use only) — ts_object","text":"is_ts_object(): Check object ts object get_type(): Get input type ts object check_type(): Check object correct type","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_union.html","id":null,"dir":"Reference","previous_headings":"","what":"Union type — ts_union","title":"Union type — ts_union","text":"Create union types. Currently accepts schemas strings.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_union.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Union type — ts_union","text":"","code":"ts_union(...)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_union.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Union type — ts_union","text":"... Zod types merge (strings)","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_union.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Union type — ts_union","text":"","code":"x <- ts_union(\"z.number()\", \"z.string()\")"},{"path":"http://tomelliott.co.nz/ts/reference/ts_void.html","id":null,"dir":"Reference","previous_headings":"","what":"Void type — ts_void","title":"Void type — ts_void","text":"type accepts null values (typically used functions return nothing).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_void.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Void type — ts_void","text":"","code":"ts_void()"},{"path":"http://tomelliott.co.nz/ts/reference/ts_void.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Void type — ts_void","text":"ts object accepts NULL.","code":""},{"path":[]},{"path":"http://tomelliott.co.nz/ts/reference/type_objects.html","id":null,"dir":"Reference","previous_headings":"","what":"Types in R and TypeScript — type_objects","title":"Types in R and TypeScript — type_objects","text":"document provides overview main types available app developers, includes main types R TypeScript counterparts.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/type_objects.html","id":"ts-objects","dir":"Reference","previous_headings":"","what":"TS objects","title":"Types in R and TypeScript — type_objects","text":"basic object ts ts_object class. represented input return types, optional default value, checking function. Input types describe zod schema objects TypeScript can pass Rserve functions. Return types describe zod schema objects Rserve functions, utilise Robj utility types rserve-ts library. return types additional properties added, namedly r_type r_attributes, handled Robj utility types. Scalar versus array (\"vector\") types: R, almost types vectors. 'rserve-js' library, primitive arrays length one converted scalars, leads issues type checking , example, return value unknown length. (x > 5) one example. solve , add n argument ts_* functions. n = 1, type takes scalar form alue. n != 1, type takes array form value (includes 0). Otherwise, type union scalar array forms. case numbers, strings, booleans.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/type_objects.html","id":"available-types","dir":"Reference","previous_headings":"","what":"Available types","title":"Types in R and TypeScript — type_objects","text":"ts_boolean: boolean value. array type Int8Array. ts_integer: integer value. array type Int32Array. Javascript native integer type, scalars represented number (ts_numeric). ts_numeric: numeric value. array type Float64Array.* ts_string: string value. array type string[]. ts_factor: factor value. array type (level1 | level2 | ... | levelN)[], type scalar form. ts_list: list value, represented named object array. ts_dataframe: data frame value, represented named object. ts_null: null value. ts_void: void value, used specifying return types functions return value.","code":""},{"path":"http://tomelliott.co.nz/ts/news/index.html","id":"ts-010---initial-release","dir":"Changelog","previous_headings":"","what":"ts 0.1.0 - Initial release","title":"ts 0.1.0 - Initial release","text":"initial developmental release ts.","code":""}]
+[{"path":"http://tomelliott.co.nz/ts/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2024 Tom Elliott Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"http://tomelliott.co.nz/ts/articles/simple-react-app.html","id":"install-the-ts-package","dir":"Articles","previous_headings":"","what":"Install the ts package","title":"Build a simple ReactJS app","text":"","code":"devtools::install_github('tmelliott/ts')"},{"path":"http://tomelliott.co.nz/ts/articles/simple-react-app.html","id":"write-the-r-code","dir":"Articles","previous_headings":"","what":"Write the R code","title":"Build a simple ReactJS app","text":"code saved file called faithful-app.R, can preview results calling functions: ’s ! ’ll use ts_compile() later create server code Typescript schema app.","code":"cat(readLines('faithful-app.R'), sep = '\\n') #> library(ts) #> #> get_hist <- ts_function( #> function(bins = ts_integer(1)) { #> h <- hist(faithful$waiting, breaks = bins, plot = FALSE) #> data.frame(x = h$mids, y = h$density) #> }, #> result = ts_dataframe(x = ts_numeric(0), y = ts_numeric(0)) #> ) #> get_smoother <- ts_function( #> function(bandwidth = ts_numeric(1)) { #> d <- density(faithful$waiting, bw = bandwidth) #> data.frame(x = d$x, y = d$y) #> }, #> result = ts_dataframe(x = ts_numeric(0), y = ts_numeric(0)) #> ) source('faithful-app.R') get_hist$call(10) #> x y #> 1 42.5 0.0029411765 #> 2 47.5 0.0161764706 #> 3 52.5 0.0242647059 #> 4 57.5 0.0176470588 #> 5 62.5 0.0102941176 #> 6 67.5 0.0073529412 #> 7 72.5 0.0198529412 #> 8 77.5 0.0397058824 #> 9 82.5 0.0404411765 #> 10 87.5 0.0169117647 #> 11 92.5 0.0036764706 #> 12 97.5 0.0007352941"},{"path":"http://tomelliott.co.nz/ts/articles/simple-react-app.html","id":"create-the-react-app","dir":"Articles","previous_headings":"","what":"Create the React app","title":"Build a simple ReactJS app","text":"’m using Vite create app, use framework. Whatever use, ’ll need able bundle code (including libraries zod). now able see default Vite app running http://localhost:5173 (similar, see console output). Now install rserve-ts zod packages:","code":"pnpm create vite faithful-demo --template vanilla-ts cd faithful-demo pnpm install pnpm run dev pnpm install rserve-ts zod"},{"path":"http://tomelliott.co.nz/ts/articles/simple-react-app.html","id":"create-the-server-code","dir":"Articles","previous_headings":"Create the React app","what":"Create the server code","title":"Build a simple ReactJS app","text":"now use ts_compile() function create two files: faithful-app.rserve.R file start Rserve instance apps functions available. faithful-app.rserve.ts contains TypeScript schema (using zod) let use R functions directly app like typescript function! ’ll send straight faithful-demo/src directory.","code":"ts_compile('faithful-app.R', filename = 'faithful-demo/src/faithful-app.rserve')"},{"path":"http://tomelliott.co.nz/ts/articles/simple-react-app.html","id":"write-the-app","dir":"Articles","previous_headings":"Create the React app","what":"Write the app","title":"Build a simple ReactJS app","text":"rest process simply requires writing TypeScript code. won’t go detail since ’s focus vignette, can see code written basic comments. Copy paste get app running.","code":"// main.ts import \"./style.css\"; import RserveClient from \"rserve-ts\"; import faithfulApp from \"./faithful-app.rserve\"; import { z } from \"zod\"; document.querySelector
(\"#app\")!.innerHTML = ` Rserve and TypeScript<\/h1> Number of bins:
Make histogram<\/button> <\/div> <\/div> <\/div> `; type FaithfulApp = z.infer
>; let getHist: FaithfulApp[\"get_hist\"] | undefined = undefined; async function connectToRserve() { const client = await RserveClient.create({ host: \"ws://localhost:6311\" }); const app = await client.ocap(faithfulApp); console.log(\"Connected to Rserve: \", app); getHist = app.get_hist; } connectToRserve(); document .querySelector(\"#counter\")! .addEventListener(\"click\", async () => { if (!getHist) return; const Nbin = parseInt( document.querySelector(\"#n\")!.value ); const hist = await getHist(Nbin); const maxY = Math.max(...hist.y); const histDiv = document.querySelector(\"#hist\")!; histDiv.innerHTML = ` ${Array.from(hist.y) .map( (yi) => `<\/div>` ) .join(\"\")} `; }); // style.css :root { font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; line-height: 1.5; font-weight: 400; color-scheme: light dark; color: rgba(255, 255, 255, 0.87); background-color: #242424; font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } a { font-weight: 500; color: #646cff; text-decoration: inherit; } a:hover { color: #535bf2; } body { margin: 0; display: flex; place-items: center; min-width: 320px; min-height: 100vh; } h1 { font-size: 3.2em; line-height: 1.1; } #app { max-width: 1280px; margin: 0 auto; padding: 2rem; text-align: center; } .logo { height: 6em; padding: 1.5em; will-change: filter; transition: filter 300ms; } .logo:hover { filter: drop-shadow(0 0 2em #646cffaa); } .logo.vanilla:hover { filter: drop-shadow(0 0 2em #3178c6aa); } .card { padding: 2em; } .read-the-docs { color: #888; } button { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; font-size: 1em; font-weight: 500; font-family: inherit; background-color: #1a1a1a; cursor: pointer; transition: border-color 0.25s; } button:hover { border-color: #646cff; } button:focus, button:focus-visible { outline: 4px auto -webkit-focus-ring-color; } input { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; font-size: 1em; font-weight: 500; font-family: inherit; background-color: #1a1a1a; color: #fff; outline: none; } input:hover { border-color: #646cff; } input:focus, input:focus-visible { outline: 4px auto -webkit-focus-ring-color; } @media (prefers-color-scheme: light) { :root { color: #213547; background-color: #ffffff; } a:hover { color: #747bff; } button { background-color: #f9f9f9; } input { background-color: #f9f9f9; color: #000; } }"},{"path":"http://tomelliott.co.nz/ts/articles/simple-react-app.html","id":"run-the-app","dir":"Articles","previous_headings":"","what":"Run the app","title":"Build a simple ReactJS app","text":"run app, start Rserve server: start Vite server: now able see app running http://localhost:5173 (similar, see console output).","code":"Rscript src/faithful-app.rserve.R pnpm run dev"},{"path":"http://tomelliott.co.nz/ts/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Tom Elliott. Author, maintainer.","code":""},{"path":"http://tomelliott.co.nz/ts/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Elliott T (2025). ts: Helper Functions Writing Type-safe Functions rserve-ts. R package version 0.1.0, http://tomelliott.co.nz/ts/.","code":"@Manual{, title = {ts: Helper Functions for Writing Type-safe Functions for rserve-ts}, author = {Tom Elliott}, year = {2025}, note = {R package version 0.1.0}, url = {http://tomelliott.co.nz/ts/}, }"},{"path":"http://tomelliott.co.nz/ts/index.html","id":"ts-write-apps-with-r-rserve-and-typescript","dir":"","previous_headings":"","what":"Helper Functions for Writing Type-safe Functions for rserve-ts","title":"Helper Functions for Writing Type-safe Functions for rserve-ts","text":"ts package makes easy users write functions can used rserve-ts applications.","code":""},{"path":"http://tomelliott.co.nz/ts/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Helper Functions for Writing Type-safe Functions for rserve-ts","text":"can install development version ts GitHub :","code":"# install.packages(\"devtools\") devtools::install_github(\"tmelliott/ts\")"},{"path":"http://tomelliott.co.nz/ts/index.html","id":"example","dir":"","previous_headings":"","what":"Example","title":"Helper Functions for Writing Type-safe Functions for rserve-ts","text":"Writing functions easy, just use ts_*() functions define formals return types. use ts_compile() generate TypeScript schemas: can import rserve-ts application. See tests/testthat/sampler example. also possible generate sourceable file deploy Rserve instance app code using ts_deploy():","code":"# demo.R library(ts) addFn <- ts_function( function(a = ts_numeric(1), b = ts_numeric(1)) a + b, result = ts_numeric(1) ) sampleFn <- ts_function( function(x = ts_character(), n = ts_integer(1)) sample(x, n), result = ts_character() ) app <- ts_function( function() { list( add = addFn, sample = sampleFn ) }, result = ts_list( add = addFn, sample = sampleFn ) ) # TODO: specify exactly which functions to export in the entry point # ts_export(app) import { Robj } from 'rserve-ts'; import { z } from 'zod'; const addFn = Robj.ocap([z.number(), z.number()], Robj.numeric(1)); const app = Robj.ocap([], Robj.list({ add: Robj.ocap(), sample: Robj.ocap() }) ); const sampleFn = Robj.ocap( [z.union([z.string(), z.array(z.string())]), z.number()], Robj.character() ); export default { addFn, app, sampleFn }; ts_deploy(app) # run with: Rscript app.rserve.R"},{"path":"http://tomelliott.co.nz/ts/reference/ts_app.html","id":null,"dir":"Reference","previous_headings":"","what":"Generate an Rserve app from a ts function — ts_app","title":"Generate an Rserve app from a ts function — ts_app","text":"Anything function simply returns . However, functions wrapped Rserve::ocap(), result subsequently wrapped ts_app().","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_app.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Generate an Rserve app from a ts function — ts_app","text":"","code":"ts_app(x)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_app.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Generate an Rserve app from a ts function — ts_app","text":"x ts function object (ts_function())","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_app.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Generate an Rserve app from a ts function — ts_app","text":"object class 'OCref', see Rserve::ocap()","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_app.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Generate an Rserve app from a ts function — ts_app","text":"","code":"f <- ts_function(function(x = ts_integer(1), y = ts_character(1)) { x + nchar(y) }, result = ts_integer(1)) app <- ts_app(f) # class of 'OCref' # this can now be used in an Rserve application, for example"},{"path":"http://tomelliott.co.nz/ts/reference/ts_character.html","id":null,"dir":"Reference","previous_headings":"","what":"Character or string type — ts_character","title":"Character or string type — ts_character","text":"Strings represented Zod schema either string (z.string()), string array (z.array(z.string())).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_character.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Character or string type — ts_character","text":"","code":"ts_character(n = -1L)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_character.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Character or string type — ts_character","text":"n length string vector. n = 1 single string expected. n = 0 length expected. n > 1 string vector length n expected.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_character.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Character or string type — ts_character","text":"ts object accepts strings string vectors length n.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_character.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Character or string type — ts_character","text":"","code":"x <- ts_character(1) x$check(\"a\") #> [1] \"a\""},{"path":"http://tomelliott.co.nz/ts/reference/ts_compile.html","id":null,"dir":"Reference","previous_headings":"","what":"Compile R functions — ts_compile","title":"Compile R functions — ts_compile","text":"Generates TypeScript schema given R function file path. path, R app also generated.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_compile.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compile R functions — ts_compile","text":"","code":"ts_compile(f, ..., name, filename)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_compile.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compile R functions — ts_compile","text":"f function file path ... Additional arguments (passed ts_deploy) name name function filename base file path write TypeScript schema R app (optional, uses [path f].rserve default). .R .ts file extensions appended automatically. \"\", output printed standard output console (see cat).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_compile.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compile R functions — ts_compile","text":"Character vector TypeScript schema, NULL writing file","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_dataframe.html","id":null,"dir":"Reference","previous_headings":"","what":"Typed dataframe — ts_dataframe","title":"Typed dataframe — ts_dataframe","text":"essentially list, elements must names length.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_dataframe.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Typed dataframe — ts_dataframe","text":"","code":"ts_dataframe(...)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_dataframe.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Typed dataframe — ts_dataframe","text":"... Named types.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_dataframe.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Typed dataframe — ts_dataframe","text":"ts object accepts data frames specified types.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_dataframe.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Typed dataframe — ts_dataframe","text":"","code":"x <- ts_dataframe(a = ts_integer(1), b = ts_character(1)) x$check(data.frame(a = 1L, b = \"a\")) #> a b #> 1 1 a"},{"path":"http://tomelliott.co.nz/ts/reference/ts_deploy.html","id":null,"dir":"Reference","previous_headings":"","what":"Deploy a ts Rserve app — ts_deploy","title":"Deploy a ts Rserve app — ts_deploy","text":"Deploy ts Rserve app","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_deploy.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Deploy a ts Rserve app — ts_deploy","text":"","code":"ts_deploy( f, file = sprintf(\"%s.rserve.R\", tools::file_path_sans_ext(f)), init = NULL, port = 6311, run = c(\"no\", \"here\", \"background\"), silent = FALSE )"},{"path":"http://tomelliott.co.nz/ts/reference/ts_deploy.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Deploy a ts Rserve app — ts_deploy","text":"f path application files file file write deployment script init Names objects (ts_functions) make available initialisation function port port deploy app run Whether run deployment script, takes values \"\", \"\", \"background\" silent Whether print deployment script","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_deploy.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Deploy a ts Rserve app — ts_deploy","text":"NULL, called open Rserve instance","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_factor.html","id":null,"dir":"Reference","previous_headings":"","what":"Typed factor — ts_factor","title":"Typed factor — ts_factor","text":"Factors integers labels. JS side, always represented string array (even one value - yay!).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_factor.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Typed factor — ts_factor","text":"","code":"ts_factor(levels = NULL)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_factor.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Typed factor — ts_factor","text":"levels character vector levels (optional).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_factor.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Typed factor — ts_factor","text":"ts object accepts factors specified levels.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_factor.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Typed factor — ts_factor","text":"","code":"x <- ts_factor(levels = c(\"a\", \"b\")) x$check(factor(\"a\", levels = c(\"a\", \"b\"))) #> [1] a #> Levels: a b if (FALSE) { # \\dontrun{ # this will fail x$check(\"a\") x$check(factor(\"c\", levels = c(\"a\", \"b\", \"c\"))) } # }"},{"path":"http://tomelliott.co.nz/ts/reference/ts_function.html","id":null,"dir":"Reference","previous_headings":"","what":"TS function definition — ts_function","title":"TS function definition — ts_function","text":"TS function definition","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_function.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"TS function definition — ts_function","text":"","code":"ts_function(f, ..., result = ts_void())"},{"path":"http://tomelliott.co.nz/ts/reference/ts_function.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"TS function definition — ts_function","text":"f R function ... argument definitions (required f specify formals) result return type (ignored overloads provided)","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_function.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"TS function definition — ts_function","text":"Defining functions core writing Rserve apps. Functions referred object capabilities (ocaps), 'objects' allow Javascript access capabilities R restricted interface. arguments can adjusted. TS functions can defined using existing (named) anonymous functions. Anonymous functions useful arguments functions can explicitly defined types formal arguments:","code":"ts_function(function(x = ts_integer(), y = ts_string()) { ... })"},{"path":"http://tomelliott.co.nz/ts/reference/ts_function.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"TS function definition — ts_function","text":"","code":"f <- ts_function(function(x = ts_integer(1), y = ts_character(1)) { x + nchar(y) }, result = ts_integer(1)) f$call(1, \"hello\") #> [1] 6"},{"path":"http://tomelliott.co.nz/ts/reference/ts_integer.html","id":null,"dir":"Reference","previous_headings":"","what":"Integer type — ts_integer","title":"Integer type — ts_integer","text":"Integers represented Zod schema either number (z.number()), Int32Array (z.instanceof(Int32Array)).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_integer.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Integer type — ts_integer","text":"","code":"ts_integer(n = -1L)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_integer.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Integer type — ts_integer","text":"n length integer vector. n = 1 single integer expected. n = 0 length expected. n > 1 integer vector length n expected.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_integer.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Integer type — ts_integer","text":"ts object accepts integer scalars vectors length n.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_integer.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Integer type — ts_integer","text":"","code":"x <- ts_integer(1) x$check(1L) #> [1] 1 if (FALSE) { # \\dontrun{ # this will fail x$check(1:10) } # }"},{"path":"http://tomelliott.co.nz/ts/reference/ts_list.html","id":null,"dir":"Reference","previous_headings":"","what":"Typed list — ts_list","title":"Typed list — ts_list","text":"list vector robjects, may may named.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_list.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Typed list — ts_list","text":"","code":"ts_list(...)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_list.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Typed list — ts_list","text":"... list types, named unnamed.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_list.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Typed list — ts_list","text":"ts object accepts lists specified types.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_list.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Typed list — ts_list","text":"","code":"x <- ts_list(a = ts_integer(1), b = ts_character(1)) x$check(list(a = 1L, b = \"a\")) #> $a #> [1] 1 #> #> $b #> [1] \"a\" #>"},{"path":"http://tomelliott.co.nz/ts/reference/ts_logical.html","id":null,"dir":"Reference","previous_headings":"","what":"Logical or boolean type — ts_logical","title":"Logical or boolean type — ts_logical","text":"Booleans represented Zod schema either boolean (z.boolean()), typed Uint8Array (z.instanceof(Uint8Array)).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_logical.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Logical or boolean type — ts_logical","text":"","code":"ts_logical(n = -1L)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_logical.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Logical or boolean type — ts_logical","text":"n length boolean vector. n = 1 single boolean expected. n = 0 length expected. n > 1 boolean vector length n expected.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_logical.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Logical or boolean type — ts_logical","text":"ts object accepts logical scalars vectors length n.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_logical.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Logical or boolean type — ts_logical","text":"","code":"x <- ts_logical(1) x$check(TRUE) #> [1] TRUE if (FALSE) { # \\dontrun{ # this will fail x$check(5) } # }"},{"path":"http://tomelliott.co.nz/ts/reference/ts_null.html","id":null,"dir":"Reference","previous_headings":"","what":"Null type — ts_null","title":"Null type — ts_null","text":"type accepts NULL. function return types, use ts_void.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_null.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Null type — ts_null","text":"","code":"ts_null()"},{"path":"http://tomelliott.co.nz/ts/reference/ts_null.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Null type — ts_null","text":"ts object accepts NULL.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_null.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Null type — ts_null","text":"","code":"x <- ts_null() x$check(NULL) #> NULL"},{"path":"http://tomelliott.co.nz/ts/reference/ts_numeric.html","id":null,"dir":"Reference","previous_headings":"","what":"Numeric type — ts_numeric","title":"Numeric type — ts_numeric","text":"Numbers represented Zod schema either number (z.number()), Float64Array (z.instanceof(Float64Array)).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_numeric.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Numeric type — ts_numeric","text":"","code":"ts_numeric(n = -1L)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_numeric.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Numeric type — ts_numeric","text":"n length numeric vector. n = 1 single number expected. n = 0 length expected. n > 1 numeric vector length n expected.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_numeric.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Numeric type — ts_numeric","text":"ts object accepts numeric scalars vectors length n.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_numeric.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Numeric type — ts_numeric","text":"","code":"x <- ts_numeric(1) x$check(1) #> [1] 1 if (FALSE) { # \\dontrun{ # this will fail x$check(c(1, 2, 3)) x$check(\"a\") } # }"},{"path":"http://tomelliott.co.nz/ts/reference/ts_object.html","id":null,"dir":"Reference","previous_headings":"","what":"Typed object (internal use only) — ts_object","title":"Typed object (internal use only) — ts_object","text":"base type typed objects, can used define custom types.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_object.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Typed object (internal use only) — ts_object","text":"","code":"ts_object( input_type = \"any\", return_type = \"any\", default = NULL, check = function() stop(\"Not implemented\"), generic = FALSE ) is_ts_object(x) get_type(x, which = c(\"input\", \"return\")) check_type(type, x)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_object.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Typed object (internal use only) — ts_object","text":"input_type type object Typescript expect send R. return_type type object Typescript expects recieve R. default default value object. check function checks object returns valid. operates R side mostly development debugging purposes. developer ensure functions return correct type object always. generic logical, TRUE object generic type. x object type get, either \"input\" \"return\" type ts object","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_object.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Typed object (internal use only) — ts_object","text":"is_ts_object(): Check object ts object get_type(): Get input type ts object check_type(): Check object correct type","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_union.html","id":null,"dir":"Reference","previous_headings":"","what":"Union type — ts_union","title":"Union type — ts_union","text":"Create union types. Currently accepts schemas strings.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_union.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Union type — ts_union","text":"","code":"ts_union(...)"},{"path":"http://tomelliott.co.nz/ts/reference/ts_union.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Union type — ts_union","text":"... Zod types merge (strings)","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_union.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Union type — ts_union","text":"","code":"x <- ts_union(\"z.number()\", \"z.string()\")"},{"path":"http://tomelliott.co.nz/ts/reference/ts_void.html","id":null,"dir":"Reference","previous_headings":"","what":"Void type — ts_void","title":"Void type — ts_void","text":"type accepts null values (typically used functions return nothing).","code":""},{"path":"http://tomelliott.co.nz/ts/reference/ts_void.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Void type — ts_void","text":"","code":"ts_void()"},{"path":"http://tomelliott.co.nz/ts/reference/ts_void.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Void type — ts_void","text":"ts object accepts NULL.","code":""},{"path":[]},{"path":"http://tomelliott.co.nz/ts/reference/type_objects.html","id":null,"dir":"Reference","previous_headings":"","what":"Types in R and TypeScript — type_objects","title":"Types in R and TypeScript — type_objects","text":"document provides overview main types available app developers, includes main types R TypeScript counterparts.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/type_objects.html","id":"ts-objects","dir":"Reference","previous_headings":"","what":"TS objects","title":"Types in R and TypeScript — type_objects","text":"basic object ts ts_object class. represented input return types, optional default value, checking function. Input types describe zod schema objects TypeScript can pass Rserve functions. Return types describe zod schema objects Rserve functions, utilise Robj utility types rserve-ts library. return types additional properties added, namedly r_type r_attributes, handled Robj utility types. Scalar versus array (\"vector\") types: R, almost types vectors. 'rserve-js' library, primitive arrays length one converted scalars, leads issues type checking , example, return value unknown length. (x > 5) one example. solve , add n argument ts_* functions. n = 1, type takes scalar form alue. n != 1, type takes array form value (includes 0). Otherwise, type union scalar array forms. case numbers, strings, booleans.","code":""},{"path":"http://tomelliott.co.nz/ts/reference/type_objects.html","id":"available-types","dir":"Reference","previous_headings":"","what":"Available types","title":"Types in R and TypeScript — type_objects","text":"ts_boolean: boolean value. array type Int8Array. ts_integer: integer value. array type Int32Array. Javascript native integer type, scalars represented number (ts_numeric). ts_numeric: numeric value. array type Float64Array.* ts_string: string value. array type string[]. ts_factor: factor value. array type (level1 | level2 | ... | levelN)[], type scalar form. ts_list: list value, represented named object array. ts_dataframe: data frame value, represented named object. ts_null: null value. ts_void: void value, used specifying return types functions return value.","code":""},{"path":"http://tomelliott.co.nz/ts/news/index.html","id":"ts-010---initial-release","dir":"Changelog","previous_headings":"","what":"ts 0.1.0 - Initial release","title":"ts 0.1.0 - Initial release","text":"initial developmental release ts. API expected change future releases tested various example applications, happen use project suggest pin version: get started, check docs site https://tomelliott.co.nz/ts/.","code":"# install.packages(\"remotes\") remotes::install_github(\"ws1/ts@0.1.0\")"}]