-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathworking.r
54 lines (44 loc) · 1.5 KB
/
working.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
library(dplyr)
library(RSclient)
iris %>%
group_by(Species) %>%
parallelize %>%
do({
# something that's better run in paralle
data.frame(result = 1)
})
system.time({
data.frame(g = sample.int(1e1, 1e7, replace = TRUE),
r = sample(2, 1e7, replace = TRUE) - 1,
x = rnorm(1e7), y = rnorm(1e7)) %>%
group_by(g) %>%
do({
m <- glm(r~x+y, family = binomial, ., control = list(maxit = 100))
data.frame(err = sqrt(mean(residuals(m)^2)))
})
})
system.time({
data.frame(g = sample.int(1e1, 1e7, replace = TRUE),
r = sample(2, 1e7, replace = TRUE) - 1,
x = rnorm(1e7), y = rnorm(1e7)) %>%
group_by(g) %>%
parallelize %>%
do({
m <- glm(r~x+y, family = binomial, ., control = list(maxit = 100))
data.frame(err = sqrt(mean(residuals(m)^2)))
})
})
library(httr)
library(defer)
wrapper <- defer(function(x)x*x)
public_opencpu_url <- "https://cloud.opencpu.org/ocpu/library/base/R/source/print"
# we're still using the same wrapper object as above
serialized_wrapper <- jsonlite::base64_enc(serialize(wrapper, NULL))
local_script_path <- tempfile(fileext = ".R")
cat(paste0("wrapper <- unserialize(jsonlite::base64_dec('", serialized_wrapper, "'))\n",
"wrapper(10)\n"),
file = local_script_path)
http_result <- httr::POST(public_opencpu_url,
body = list(file = upload_file(local_script_path)))
content(http_result, 'text')
#> [1] "$value\n[1] 29688.67\n\n$visible\n[1] TRUE\n\n"