more demo use
This commit is contained in:
parent
fa5be168c0
commit
dfaeabec05
@ -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))
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
)
|
||||
|
||||
@ -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)
|
||||
```
|
||||
|
||||
10
README.md
10
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<Numeric>;
|
||||
#> const myfun = (x: number | number[]) => Promise<Numeric<1>)>;
|
||||
```
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user