From dfaeabec05e9696d9ba0dae0ed8d587618f35819 Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 24 Jul 2024 11:52:09 +1200 Subject: [PATCH] more demo use --- R/function.R | 2 +- R/types.R | 6 ++++-- README.Rmd | 8 ++++++-- README.md | 10 ++++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/R/function.R b/R/function.R index 400a7fc..a7f94e6 100644 --- a/R/function.R +++ b/R/function.R @@ -23,7 +23,7 @@ ts_function <- function(f, ..., result = NULL) { } fn <- function(...) { - mc <- match.call() + mc <- match.call(f) x <- parse_args(args, mc) result$check(do.call(f, x)) } diff --git a/R/types.R b/R/types.R index fe831a3..03002b7 100644 --- a/R/types.R +++ b/R/types.R @@ -74,8 +74,10 @@ ts_numeric <- function(n = -1L) { n_type(n, "number"), n_type_fun(n, "Numeric"), check = function(x) { - if (!is.numeric(x)) stop("Expected a number") - if (n > 0 && length(x) != n) stop("Expected a number of length ", n) + if (!is.numeric(x)) stop("Expected a number", call. = FALSE) + if (n > 0 && length(x) != n) { + stop("Expected a number of length ", n, , call. = FALSE) + } x } ) diff --git a/README.Rmd b/README.Rmd index 80a7ba3..bff5800 100644 --- a/README.Rmd +++ b/README.Rmd @@ -94,9 +94,13 @@ type App = { Here's what's currently working: -```{r} +```{r, error = TRUE} library(ts) -myfun <- ts_function(mean, x = ts_numeric(), result = ts_numeric()) +myfun <- ts_function(mean, x = ts_numeric(), result = ts_numeric(1)) +myfun(1:5) + +myfun("hello world") + ts_compile(myfun) ``` diff --git a/README.md b/README.md index 530fde5..dec50b8 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,13 @@ Here’s what’s currently working: ``` r library(ts) -myfun <- ts_function(mean, x = ts_numeric(), result = ts_numeric()) +myfun <- ts_function(mean, x = ts_numeric(), result = ts_numeric(1)) +myfun(1:5) +#> [1] 3 + +myfun("hello world") +#> Error: Expected a number + ts_compile(myfun) -#> const myfun = (x: number | number[]) => Promise; +#> const myfun = (x: number | number[]) => Promise)>; ```