-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsratch.R
94 lines (79 loc) · 2.01 KB
/
sratch.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# promise handlers could potentially go into
# the environment bindings
# e <- new.env()
# f <- function(var) {
# env_bind_fns(e, !!enexpr(var) := function(val) {cat("hello\n"); 1})
# }
# e$x <- 1
# e$x
# env_bind_fns(e, x = function(val) {cat("hello\n"); 1})
# e$x
#
# yl <- list(y = 1)
# env_bind_fns(e, y = function() {1})
# eval(expr(x + y), e)
# find name of function in R
f <- function() {
name <- match.call()[[1]]
print(as.character(name))
}
# substitute variables from environment
# possible use: send values from reactive into
# future instead of reactives themselves
e <- new.env()
e$x <- 1
e$y <- 1
env_bind_fns(e, y = function(val) {print("getting called"); 1})
# binding is called
eval(parse_expr("y"), e)
eval(expr(x + y + 1), e)
1
# binding is also called
substitute(x + y + 1, e)
e$.parsed <- parse_expr("x + y + 1")
eval(substitute(substitute(.parsed, e), e))
# variables within functions work too
# need to check why that doesn't work with promise
substitute(f <- function(a) {a + y}, e)
# # idea:
# on <- reactiveVal()
# observeEvent(input$boxn,{
# e$.parsed <- parse_expr(input$boxn)
# subbed_expr <- eval(substitute(substitute(.parsed, e), e))
# future(eval(subbed_expr)) %...>%
# on()
# })
# output$outn <- renderPrint({
# on()
# })
#
# # TODO: get future to eval an expression
# expr <- parse_expr("{Sys.sleep(5); head(cars)}")
# f <- future(eval(expr))
# value(f)
# # JS function to block thread. It kills all
# # observable cells, meaning they are NOT operating
# # on cell based promises, but interacting with promise delays
# function sleep(seconds)
# {
# var e = new Date().getTime() + (seconds * 1000);
# while (new Date().getTime() <= e) {}
# }
# # get name of parent function
# foo1 <- function() {
# # match.call()[[1]]
# as.character(sys.calls()[[sys.nframe()-1]])
# }
#
# foo2 <- function() {
# foo1()
# }
#
# bar <- function() {
# foo2()
# }
library(rlang)
e <- new.env()
e$y <- 1
env_bind_fns(e, y = function(val) {print("getting called"); 1})
eval(expr(x + y + 1), e)