diff --git a/pkgdown.yml b/pkgdown.yml index 4870ef9..7b01949 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -3,7 +3,7 @@ pkgdown: 2.1.1 pkgdown_sha: ~ articles: simple-react-app: simple-react-app.html -last_built: 2025-02-07T00:48Z +last_built: 2025-02-24T01:38Z urls: reference: http://tomelliott.co.nz/ts/reference article: http://tomelliott.co.nz/ts/articles diff --git a/reference/index.html b/reference/index.html index 2b6a854..54c190d 100644 --- a/reference/index.html +++ b/reference/index.html @@ -145,7 +145,7 @@ ts_object() is_ts_object() get_type() check_type() -
Typed object
+
Typed object (internal use only)
ts_union() diff --git a/reference/ts_app.html b/reference/ts_app.html index 8a11afd..3797867 100644 --- a/reference/ts_app.html +++ b/reference/ts_app.html @@ -59,7 +59,20 @@ and the result is subsequently wrapped with ts_app().

A ts function object (ts_function())

+
+

Value

+

An object of class 'OCref', see Rserve::ocap()

+
+
+

Examples

+
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
+
+
diff --git a/reference/ts_character.html b/reference/ts_character.html index c6ec422..a0fbd9e 100644 --- a/reference/ts_character.html +++ b/reference/ts_character.html @@ -61,6 +61,13 @@ or a string array (z.array(z.string())).

A ts object that accepts strings or string vectors of length n.

+
+

Examples

+
x <- ts_character(1)
+x$check("a")
+#> [1] "a"
+
+
diff --git a/reference/ts_dataframe.html b/reference/ts_dataframe.html index 9a2dc60..61f157f 100644 --- a/reference/ts_dataframe.html +++ b/reference/ts_dataframe.html @@ -58,6 +58,14 @@

A ts object that accepts data frames with the specified types.

+
+

Examples

+
x <- ts_dataframe(a = ts_integer(1), b = ts_character(1))
+x$check(data.frame(a = 1L, b = "a"))
+#>   a b
+#> 1 1 a
+
+
diff --git a/reference/ts_factor.html b/reference/ts_factor.html index 1c155ef..70ba6df 100644 --- a/reference/ts_factor.html +++ b/reference/ts_factor.html @@ -58,6 +58,20 @@

A ts object that accepts factors with the specified levels.

+
+

Examples

+
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")))
+} # }
+
+
diff --git a/reference/ts_function.html b/reference/ts_function.html index 662a16e..b6cecf5 100644 --- a/reference/ts_function.html +++ b/reference/ts_function.html @@ -73,6 +73,15 @@ can explicitly be defined with their types as formal arguments:

ts_function(function(x = ts_integer(), y = ts_string()) { ... })

+
+

Examples

+
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
+
+
diff --git a/reference/ts_integer.html b/reference/ts_integer.html index 9e8fa54..4f83e10 100644 --- a/reference/ts_integer.html +++ b/reference/ts_integer.html @@ -61,6 +61,18 @@ or a Int32Array (z.instanceof(Int32Array)).

A ts object that accepts integer scalars or vectors of length n.

+
+

Examples

+
x <- ts_integer(1)
+x$check(1L)
+#> [1] 1
+
+if (FALSE) { # \dontrun{
+# this will fail
+x$check(1:10)
+} # }
+
+
diff --git a/reference/ts_list.html b/reference/ts_list.html index 531ed6d..5ebab84 100644 --- a/reference/ts_list.html +++ b/reference/ts_list.html @@ -58,6 +58,18 @@

A ts object that accepts lists with the specified types.

+
+

Examples

+
x <- ts_list(a = ts_integer(1), b = ts_character(1))
+x$check(list(a = 1L, b = "a"))
+#> $a
+#> [1] 1
+#> 
+#> $b
+#> [1] "a"
+#> 
+
+
diff --git a/reference/ts_logical.html b/reference/ts_logical.html index ce55356..45e846b 100644 --- a/reference/ts_logical.html +++ b/reference/ts_logical.html @@ -68,6 +68,7 @@ or a typed Uint8Array (z.instanceof(Uint8Array)).

#> [1] TRUE if (FALSE) { # \dontrun{ +# this will fail x$check(5) } # } diff --git a/reference/ts_null.html b/reference/ts_null.html index 9e55d81..6785d86 100644 --- a/reference/ts_null.html +++ b/reference/ts_null.html @@ -1,5 +1,5 @@ -Null type — ts_null • ts +Null type — ts_null • ts Skip to contents @@ -37,7 +37,7 @@
-

This is a type that only accepts NULL.

+

This is a type that only accepts NULL. For function return types, use ts_void.

@@ -50,6 +50,13 @@

A ts object that only accepts NULL.

+
+

Examples

+
x <- ts_null()
+x$check(NULL)
+#> NULL
+
+
diff --git a/reference/ts_numeric.html b/reference/ts_numeric.html index b60cf38..585b4cd 100644 --- a/reference/ts_numeric.html +++ b/reference/ts_numeric.html @@ -61,6 +61,19 @@ or a Float64Array (z.instanceof(Float64Array)).

A ts object that accepts numeric scalars or vectors of length n.

+
+

Examples

+
x <- ts_numeric(1)
+x$check(1)
+#> [1] 1
+
+if (FALSE) { # \dontrun{
+# this will fail
+x$check(c(1, 2, 3))
+x$check("a")
+} # }
+
+
diff --git a/reference/ts_object.html b/reference/ts_object.html index 28ce39b..b5ce55d 100644 --- a/reference/ts_object.html +++ b/reference/ts_object.html @@ -1,5 +1,5 @@ -Typed object — ts_object • tsTyped object (internal use only) — ts_object • ts Skip to contents @@ -33,7 +33,7 @@ custom types.">
diff --git a/reference/ts_union.html b/reference/ts_union.html index e506c10..26b2a81 100644 --- a/reference/ts_union.html +++ b/reference/ts_union.html @@ -50,10 +50,15 @@
...
-

Types to merge

+

Zod types to merge (as strings)

+
+

Examples

+
x <- ts_union("z.number()", "z.string()")
+
+
diff --git a/reference/ts_void.html b/reference/ts_void.html index d835202..9c95464 100644 --- a/reference/ts_void.html +++ b/reference/ts_void.html @@ -52,6 +52,10 @@ functions that return nothing).

Value

A ts object that accepts NULL.

+
+

See also

+

ts_null

+
diff --git a/search.json b/search.json index 778145a..a72da91 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"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: