minor edits
This commit is contained in:
parent
bf50157ad9
commit
2866bed187
@ -27,7 +27,7 @@ ts_compile.ts_function <- function(f, ..., name = deparse(substitute(f))) {
|
||||
#' @export
|
||||
ts_compile.character <- function(
|
||||
f,
|
||||
file = sprintf("%s.d.ts", tools::file_path_sans_ext(f))) {
|
||||
file = sprintf("%s.rserve.ts", tools::file_path_sans_ext(f))) {
|
||||
if (length(f) > 1) {
|
||||
return(sapply(f, ts_compile))
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
library(ts)
|
||||
|
||||
fn_mean <- ts_function(mean, x = ts_numeric(), result = ts_numeric(1))
|
||||
fn_first <- ts_function(function(x = ts_character()) x[1],
|
||||
result = ts_character(1)
|
||||
|
||||
@ -4,41 +4,43 @@ test_that("anonomous functions", {
|
||||
result = ts_numeric(1)
|
||||
)
|
||||
|
||||
ts_compile(add)
|
||||
|
||||
# expect_equal(add$call(1, 2), 3)
|
||||
# expect_error(add$call("a", 2))
|
||||
add_c <- ts_compile(add)
|
||||
expect_equal(add_c, "const add = Robj.ocap([z.number(), z.number()], Robj.numeric(1));")
|
||||
})
|
||||
|
||||
test_that("Complex functions", {
|
||||
get_sample <- ts_function(
|
||||
function(n = ts_numeric(1)) {
|
||||
sample(values, n)
|
||||
},
|
||||
result = ts_numeric()
|
||||
)
|
||||
# test_that("Complex functions", {
|
||||
# get_sample <- ts_function(
|
||||
# function(n = ts_numeric(1)) {
|
||||
# sample(values, n)
|
||||
# },
|
||||
# result = ts_numeric()
|
||||
# )
|
||||
|
||||
sampler <- ts_function(
|
||||
function(values = ts_numeric()) {
|
||||
list(
|
||||
get = get_sample$copy(),
|
||||
set = ts_function(
|
||||
function(value = ts_numeric()) {
|
||||
values <<- value
|
||||
}
|
||||
)
|
||||
)
|
||||
},
|
||||
result = ts_list(
|
||||
get = get_sample,
|
||||
set = ts_function(NULL, value = ts_numeric())
|
||||
)
|
||||
)
|
||||
# sampler <- ts_function(
|
||||
# function(values = ts_numeric()) {
|
||||
# list(
|
||||
# get = get_sample$copy(),
|
||||
# set = ts_function(
|
||||
# function(value = ts_numeric()) {
|
||||
# values <<- value
|
||||
# }
|
||||
# )
|
||||
# )
|
||||
# },
|
||||
# result = ts_list(
|
||||
# get = get_sample,
|
||||
# set = ts_function(NULL, value = ts_numeric())
|
||||
# )
|
||||
# )
|
||||
|
||||
ts_compile(sampler)
|
||||
})
|
||||
# sampler_c <- ts_compile(sampler)
|
||||
# s <- sampler_c(1:10)
|
||||
# expect_equal()
|
||||
# })
|
||||
|
||||
test_that("Compile files", {
|
||||
on.exit(if (file.exists("app.d.ts")) unlink("app.d.ts"))
|
||||
res <- ts_compile("app.R")
|
||||
f <- tempfile(fileext = ".rserve.ts")
|
||||
on.exit(unlink(f))
|
||||
res <- ts_compile("app.R", file = f)
|
||||
expect_true(file.exists(f))
|
||||
})
|
||||
|
||||
5
tests/testthat/test-deploy.R
Normal file
5
tests/testthat/test-deploy.R
Normal file
@ -0,0 +1,5 @@
|
||||
test_that("Deploy converts ts functions into valid ocap lists", {
|
||||
on.exit(if (file.exists("app.rserve.R")) unlink("app.rserve.R"))
|
||||
ts_deploy("app.R")
|
||||
expect_true(file.exists("app.rserve.R"))
|
||||
})
|
||||
@ -1,25 +0,0 @@
|
||||
test_that("Deploy converts ts functions into valid ocap lists", {
|
||||
get_sample <- ts_function(
|
||||
function(n = ts_numeric(1)) {
|
||||
sample(values, n)
|
||||
},
|
||||
result = ts_numeric()
|
||||
)
|
||||
|
||||
sampler <- ts_function(
|
||||
function(values = ts_numeric()) {
|
||||
list(
|
||||
get = get_sample$copy(),
|
||||
set = ts_function(
|
||||
function(value = ts_numeric()) {
|
||||
values <<- value
|
||||
}
|
||||
)
|
||||
)
|
||||
},
|
||||
result = ts_list(
|
||||
get = get_sample,
|
||||
set = ts_function(NULL, value = ts_numeric())
|
||||
)
|
||||
)
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user