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
|
#' @export
|
||||||
ts_compile.character <- function(
|
ts_compile.character <- function(
|
||||||
f,
|
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) {
|
if (length(f) > 1) {
|
||||||
return(sapply(f, ts_compile))
|
return(sapply(f, ts_compile))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
library(ts)
|
|
||||||
|
|
||||||
fn_mean <- ts_function(mean, x = ts_numeric(), result = ts_numeric(1))
|
fn_mean <- ts_function(mean, x = ts_numeric(), result = ts_numeric(1))
|
||||||
fn_first <- ts_function(function(x = ts_character()) x[1],
|
fn_first <- ts_function(function(x = ts_character()) x[1],
|
||||||
result = ts_character(1)
|
result = ts_character(1)
|
||||||
|
|||||||
@ -4,41 +4,43 @@ test_that("anonomous functions", {
|
|||||||
result = ts_numeric(1)
|
result = ts_numeric(1)
|
||||||
)
|
)
|
||||||
|
|
||||||
ts_compile(add)
|
add_c <- ts_compile(add)
|
||||||
|
expect_equal(add_c, "const add = Robj.ocap([z.number(), z.number()], Robj.numeric(1));")
|
||||||
# expect_equal(add$call(1, 2), 3)
|
|
||||||
# expect_error(add$call("a", 2))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test_that("Complex functions", {
|
# test_that("Complex functions", {
|
||||||
get_sample <- ts_function(
|
# get_sample <- ts_function(
|
||||||
function(n = ts_numeric(1)) {
|
# function(n = ts_numeric(1)) {
|
||||||
sample(values, n)
|
# sample(values, n)
|
||||||
},
|
# },
|
||||||
result = ts_numeric()
|
# result = ts_numeric()
|
||||||
)
|
# )
|
||||||
|
|
||||||
sampler <- ts_function(
|
# sampler <- ts_function(
|
||||||
function(values = ts_numeric()) {
|
# function(values = ts_numeric()) {
|
||||||
list(
|
# list(
|
||||||
get = get_sample$copy(),
|
# get = get_sample$copy(),
|
||||||
set = ts_function(
|
# set = ts_function(
|
||||||
function(value = ts_numeric()) {
|
# function(value = ts_numeric()) {
|
||||||
values <<- value
|
# values <<- value
|
||||||
}
|
# }
|
||||||
)
|
# )
|
||||||
)
|
# )
|
||||||
},
|
# },
|
||||||
result = ts_list(
|
# result = ts_list(
|
||||||
get = get_sample,
|
# get = get_sample,
|
||||||
set = ts_function(NULL, value = ts_numeric())
|
# 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", {
|
test_that("Compile files", {
|
||||||
on.exit(if (file.exists("app.d.ts")) unlink("app.d.ts"))
|
f <- tempfile(fileext = ".rserve.ts")
|
||||||
res <- ts_compile("app.R")
|
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